1
有人可以解释如何做嵌套的词典理解?Python嵌套的词典理解集
>> l = [set([1, 2, 3]), set([4, 5, 6])]
>> j = dict((a, i) for a in s for i, s in enumerate(l))
>> NameError: name 's' is not defined
我也喜欢:
>> j
>> {1:0, 2:0, 3:0, 4: 1, 5: 1, 6: 1}
我只是问了一个关于previous question一个简单的字典理解其中的发电机功能括号减少。最左边理解中的s
怎么不被识别?
这工作。不过,我在手册(http://docs.python.org/tutorial/datastructures.html)中看到,“嵌套列表理解必须特别小心:为了避免在嵌套列表解析时产生理解,请阅读从右到左“。为什么不适用? – ash 2011-01-09 11:50:12