List comprehension...

Magnus L. Hetland mlh at vier.idi.ntnu.no
Sun Dec 12 19:39:12 EST 1999


Is list comprehension on its way into the language? Or is that just a
rumour, based on Greg's patch?

And - as allways, I can't leave the syntax alone without a suggestion
of my own... Greg's patch works like this (among other things):

  [(i, s) for i in nums for s in strs]

To me, this sounds a bit like

  [(i, s) for i in [nums for s in strs]]

which I guess doesn't give much meaning. I think the syntax would be
clearer (and more natural language-like) with an "and" instead of the
"for"s, after the first one. The first ones marks that this is the
list of (i, s) for all of the "i"s and all of the "s"s given. Thus:

  [(i, s) for i in nums and s in strs]

--

  Magnus          Echelon jamming noise:
  Lie             FBI CIA NSA Handgun Assault Bomb Drug Terrorism
  Hetland         Special Forces Delta Force AK47 Hillary Clinton 



More information about the Python-list mailing list