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
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to