1 つ以上の単語がリストに含まれているかどうかを確認する関数を定義しましたが、正常に動作しますが、コードをどのように変更する必要があるかを理解しようとしています。単語がリストにあります。これらは、私がいじってきた2つの別々の機能です:
これはブール値のないもので、単語とテキストに表示されるかどうかを完全に出力しますが、関数はブール値を出力しません (出力するだけで、少し面倒です)
def isword(file):
wordlist=input("Which word(s) would you like to check for in the text? ")
wordlist=wordlist()
file=chopup(file) ##This is another function of mine that splits a string(file) into a list
for n in range(0,len(wordlist)):
word=wordlist[n]
n+=1
word=word.lower() ##so case doesn't matter when the person enters the word(s)
if word in file:
print(word, ":TRUE")
for i in range(0,len(file)):
if file[i]==word:
print(i)
else:
print(word," :FALSE")
これはブール値を出力しますが、1 つの単語のみです。出力としてブール値のリストを取得し、印刷しないようにそれらを組み合わせる方法を考えています
def isword(file):
a=True
wordlist=input("Which word(s) would you like to check for in the text? ")
wordlist=wordlist()
file=chopup(file) ##This is another function of mine that splits a string(file) into a list
for n in range(0,len(wordlist)):
word=wordlist[n]
n+=1
word=word.lower()
if word in file:
a=a
else:
a=False
return(a)
私はこれで終わりました、それはかなりうまくいきます(私の変数/関数名は実際にはプロジェクトでフランス語です。これはフランスの大学での宿題のためです)
def presmot(fichier):
result=[]
listemots=input("Entrez le/les mots dont vous voulez vérifier la présence : ")
listemots=listemots.split()
fichier=decoupage(fichier)
for n in range(0,len(listemots)):
mot=listemots[n]
mot=mot.lower()
def testemot(mot):
a=True
if mot in fichier:
a=a
else:
a=False
return(a)
result=[(mot,testemot(mot)) for mot in listemots]
return(result)
唯一厄介なことは、ブール値が英語で表示されることです。