[Tutor] build list of non-empty variables
Tim Golden
mail at timgolden.me.uk
Wed Jul 9 21:11:25 CEST 2008
Alan Gauld wrote:
> In fact I guess you could say that the new definition of a list
> comprehension is
>
> [ generator expression]
Well, not if sure if you meant that literally, but
it's certainly not: that would be a list whose one
item was a generator expression:
<code>
squares = (x * x for x in range (10))
l = [squares]
print len (l)
print l[0]
</code>
But a list comp *is* (in effect) the same as:
<code>
squares = (x * x for x in range (10))
l = list (squares)
print len (l)
print l[0]
</code>
TJG
More information about the Tutor
mailing list