iterator expression - please explain
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Mon May 24 04:09:10 EDT 2004
Helmut Jarausch wrote:
> Hi,
>
> with Python 2.4a0 (CVS 2004/05/24)
> I get
>
> def myfun(myarg):
> for z in myarg:
> print z
>
> myfun(x^2 for x in xrange(10))
> 2
> 3
> 0
> 1
> 6
> 7
> 4
> 5
> 10
> 11
>
> I expected the sequence 0,1,4,9,....
> What am I missing and what's going on here?
^ is the bitwise exclusive or operator. You want exponentiation ...
which is **.
myfun(x**2 for x in xrange(10))
Tim Delaney
More information about the Python-list
mailing list