list() strange behaviour

ast ast at invalid
Sat Jan 23 02:54:18 EST 2021


Le 20/12/2020 à 21:00, danilob a écrit :

> 
> 
> b = ((x[0] for x in a))
> 

There is a useless pair of parenthesis

b = (x[0] for x in a)

b is a GENERATOR expression

first list(b) calls next method on b repetedly until b is empty.
So it provides the "content" of b

second list(b) provides nothing since b is empty
(there is no reset on generators)






More information about the Python-list mailing list