[Tutor] implied tuple in a list comprehension

Alan Gauld alan.gauld at btinternet.com
Fri Aug 2 09:46:21 CEST 2013


On 02/08/13 08:32, Jim Mooney wrote:

> x = [idx, word for idx, word in S] #syntax error
> # Why can I imply a tuple after the for, but not before?

How should Python interpret this?

As

x = [idx, (word for idx, word in S)]

Or

x = [(idx, word) for idx, word in S]

It's ambiguous.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list