iterator expression - please explain

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Mon May 24 04:12:35 EDT 2004


Erik Max Francis wrote:

> Helmut Jarausch wrote:
> 
>> myfun(x^2 for x in xrange(10))
> 	...
>> I expected the sequence  0,1,4,9,....
>> What am I missing and what's going on here?
> 
> ^ is the bitwise xor operator.  You wanted **.  (Although what you
> wrote above isn't legal anyway.)

Note that Helmut is using 2.4 - that's a valid generator expression in
the function call.

Tim Delaney




More information about the Python-list mailing list