我试图创建一个简单的文字游戏,我需要检查玩家写的单词是否在字典中。
目前,我可以逐行检查它,但它不是很有效,所以我希望有更好的方法
import csv
word = raw_input('write your word')
def dict_test(word):
with open('/home/patryk/Pulpit/slownik.csv', 'r') as dictionary:
reader = csv.reader(dictionary, delimiter = ' ')
for row in reader:
if word not in row:
print word + ' it doesnt exist in dictionary'
elif word in row:
print word + ' ### OK ### '
dict_test(word)