List comprehension...
Magnus L. Hetland
mlh at vier.idi.ntnu.no
Mon Dec 13 17:29:48 EST 1999
Greg Ewing <greg.ewing at compaq.com> writes:
> "Magnus L. Hetland" wrote:
> >
> > [(i, s) for i in nums and s in strs]
>
> That would be ambiguous, because it could be parsed as
>
> [(i, s) for i in (nums and s in strs)]
Which, in the case that nums is not an empty list, would be
[(i, s) for i in nums]
IC. Oh, well... But what about:
[(i, s) for i in nums, and s in strs]
This is still grammatically correct English, AFAIK... And the ", and"
constellation does not have another valid interpretation, does it?
(Though it might not be really pretty...)
>
> It *might* be feasible to use
>
> [(i, s) for i in nums and for s in strs]
Nice. Much less confusing than just using the *for* directly.
(Of course, any mechanisms of parallel iteration might be used here if
they appear... Like [(i, s) for i, s in nums, strs] or something)
> If I get a spare moment or two one day I'll try this
> and see whether the parser chokes. (Python's parser
> is a bit strange - it's hard to predict what it can
> handle and what it can't.)
Good :)
>
> Greg
--
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