谁能解释一下如何进行嵌套字典理解?
>> j = dict(((x+y,0) for x in 'cd') for y in 'ab')
>> {('ca', 0): ('da', 0), ('cb', 0): ('db', 0)}
我会喜欢:
>> j
>> {'ca':0, 'cb':0, 'da':0, 'db':0}
谢谢!
最佳答案
dict((x+y,0) for x in 'cd' for y in 'ab')
关于Python嵌套字典理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4638889/