Hi all

This is purely academic, but I would like to understand the following -

>>>
>>> a = [('x', 'y')]
>>>
>>> s = []
>>> for b, c in a:
...   s.append((b, c))
...
>>> s
[('x', 'y')]


This is what I expected.

>>>
>>> s = []
>>> s.append(((b, c) for b, c in a))
>>> s
[<generator object <genexpr> at 0x0000019FC3F863C0>]
>>>

I expected the same as the first one.

I understand the concept that a generator does not return a value until you call next() on it, but I have not grasped the essential difference between the above two constructions.

TIA for any insights.

Frank Millman

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to