我有以下程序,我想在我的文本文件中找到例如字符串“浅粉色”!我使用word==' '.join(['light','pink'])
它,它不起作用。
from operator import itemgetter
def mmetric1(file):
words_gen = (word.lower() for line in open("test.txt")
for word in line.split())
words = {}
for word in words_gen:
if (word=='aqua')or(word=='azure')or(word=='black')or(word=='light pink'):
words[word] = words.get(word, 0) + 1
top_words = sorted(words.items(), key=itemgetter(1))
for word, frequency in top_words:
print ("%s : %d" % (word, frequency))