Python嵌套字典理解 [英] Python nested dict comprehension
本文介绍了Python嵌套字典理解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以解释嵌套字典的理解方式吗?
Can someone explain how to do nested dict comprehensions?
>> 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嵌套字典理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文