我编写了一个函数来解析我创建的缩略语和词义词典。但对于较长的缩略语来说,这是行不通的。我想是找到了第一件,然后吐出来的。我希望它接受整个输入,并返回响应该输入的值。单字母和双字母主要起作用,但较长的内容是不可行的。
我的键的例子:值{'b00n':‘新的人’,'hv':‘hv’,'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发布于 2016-11-14 22:02:02
缩写是一个字符串,当你把它变成一个列表时,你会得到每个字母的列表:
>>> abbrev = 'one, two, three'
>>> list(abbrev)
['o', 'n', 'e', ',', ' ', 't', 'w', 'o', ',', ' ', 't', 'h', 'r', 'e', 'e']你可能会想要这样的东西:
>>> abbrev.split(',')
['one', ' two', ' three']https://stackoverflow.com/questions/40598513
复制相似问题