1
是的,我问了很多问题。所以我写了这个函数来解析我创建的缩写词和含义词典。但它不适用于更长的缩写。我认为它找到了第一个片断并将其吐出。我希望它接受整个输入并返回对此作出响应的值。单个字母和双字母大多是工作,但更长的东西是不行的。 ['new'','hv':['have'],'wuwtb':['你想谈什么'],''''','''',''''''''''''''''''''''''''''''''''''''''''''''''''' l8rz“:”以后“],‘JHM’:”刚刚抱我'],用多个键正确解析字典
def main():
game = True
myDict = CreateDictionary('textToEnglish.csv')
print(myDict)
while game == True:
abbrev = input("Please enter text abbreviations seperated by comma:")
newList = list(abbrev)
print([v for k, v in myDict.items() if k in newList])
answer = input("Would you like to input more abbreviations? yes(y) or no(n):")
if answer == "y":
game = True
else:
game = False
另外,你应该总是比较布尔值和'is',所以不是“while game == True”使用“while game is True”。 作为一个单独的风格笔记,我会建议使用“while game”而不是“while game is True”,因为第一个更简洁(尽管你可能会认为第二个更具可读性)。 – Tyg13