返回列表中字符串的ASCII码

问题描述 投票:0回答:1

我正在尝试编写代码,该代码接受字符串列表,并返回包含字符串作为键的字典和作为值的相应字符代码列表的字典。我正在使用字典理解,这就是我所拥有的。

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. 

请告知。

我正在尝试编写代码,该代码接受字符串列表,并返回包含字符串作为键的字典和作为值的相应字符代码列表的字典。我正在使用字典...

python variable-assignment
1个回答
0
投票

尝试使用字典理解:

© www.soinside.com 2019 - 2024. All rights reserved.