我正在尝试编写代码,该代码接受字符串列表,并返回包含字符串作为键的字典和作为值的相应字符代码列表的字典。我正在使用字典理解,这就是我所拥有的。
def get_code(words):
ascii = {}
ascii = [[ord(ch) for ch in word] for word in words]
return ascii
使用]测试后>
words = ['yes','no'], i get [[121, 101, 115], [110, 111]] as the output. This {'yes': [121, 101, 115], 'no': [110, 111]} is what i want to get.
请告知。
我正在尝试编写代码,该代码接受字符串列表,并返回包含字符串作为键的字典和作为值的相应字符代码列表的字典。我正在使用字典...
尝试使用字典理解: