I tried using a nested generator comprehension over dictionary with lists as the stored values and observed the following strange (to me) behavior:
Python 2.6.5 (r265:79063, Oct 1 2012, 22:07:21)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> dummy = {1:[1,2,3],2:[2,3,4],3:[3,4,5]}
>>> a = (d for _,d in dummy.iteritems())
>>> a.next()
[1, 2, 3]
>>> a.next()
[2, 3, 4]
>>> a.next()
[3, 4, 5]
>>> a.next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
This makes sense. What follows does not (at least to me)
>>> aa = (dd for dd in (d for _,d in dummy.iteritems()))
>>> aa.next()
[1, 2, 3]
>>> aa.next()
[2, 3, 4]
>>> aa.next()
[3, 4, 5]
>>> aa.next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
Why does my (attempted) nested generator comprehension behave the same way as the non-nested version? I would have expected each aa.next() to give a single element result, instead of a list.
Your inner generator returns a single value each time it is iterated, and each value is a list. You will need to use an actual nested structure instead.