[Tutor] implied tuple in a list comprehension
Jim Mooney
cybervigilante at gmail.com
Fri Aug 2 09:32:20 CEST 2013
# python 3 on win 7
S = enumerate('all good dogs eat shoes'.split())
# I'm curious why this works:
x = [(idx, word) for idx, word in S]
# but this doesn't:
x = [idx, word for idx, word in S] #syntax error
# Why can I imply a tuple after the for, but not before?
--
Jim
Just remember, food faddists, the first three letters of Diet spells DIE!
More information about the Tutor
mailing list