开发者

Trying to create a look-up table but one array has an apostrophe in front

I'm trying to create a look-up table between two arrays which I've created from a text file.

One is letters, LET = '[AS, DF, EG, ET, AS]' The other is numbers, NUM = [1,3,1,0,6]

I want to be able to retrieve the number corresponding with the pair of letters.

How can I do this?

I think my problem has something to do with the fact that the LET array is a string as 开发者_运维技巧indicated by the " ' ". Is there any way I can change this and then tuple the two lists?


'[AS, DF, EG, ET, AS]' is a string. You need to fix your code so it is a list of strings as imm suggests.

Now you can use zip() with the two lists to make a dictionary

>>> LET = ['AS','DF','EG','ET','AS']
>>> NUM = [1,3,1,0,6]
>>> dict(zip(LET, NUM))
{'DF': 3, 'ET': 0, 'AS': 6, 'EG': 1}

note that there is only one of the values for 'AS' in the dictionary since you can't have duplicate keys

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜