NEWBIE: for statement in "dive into python" gives syntax error.

Hans Nowak wurmy at earthlink.net
Tue Jul 23 15:52:48 EDT 2002


Mack wrote:

>>>>[elem*2 for elem in li]
>>>
>   File "<stdin>", line 1
>     [elem*2 for elem in li]
>               ^
> is what i'm getting. Is my python too old? Is something else wrong?
> I've just cut and pasted from the tutorial into python ide.

That's a list comprehension, which wasn't available in 1.5.2. I think it first 
appeared in 2.0. Upgrading to a more recent Python version should fix this.

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/




More information about the Python-list mailing list