[Python-Dev] zip() and list-comprehension with commas

Peter Schneider-Kamp peter@schneider-kamp.de
Wed, 12 Jul 2000 10:59:09 +0000

Ka-Ping Yee wrote:
> On Wed, 12 Jul 2000, Peter Schneider-Kamp wrote:
> > +1 on this. no performance hit (probably a small gain),
> > "zip" is imho the right name (see e.g. haskell).
> Indeed, a nice coincidence. :)

I am still thinking about higher order functions in Python:
e.g.: map(+ 1, [1, 2, 3]) instead of map(lambda x: x + 1, [1, 2, 3])
don't have a clue how to do that yet.

> Alas, the vertical bar is already a bitwise-or operator, and
> couldn't safely be placed next to the <expr>.
> Semicolon might be worth considering here, actually: [f(x); for x in l]

Better than just a comma anyway. Okay for me.

>     [(x, y), for x in list1, if x > 1, for y in list2, if y > 2]
> The first would produce [(2, 3), (3, 3)], and the second would

> It would have to be written:
>     [(x, y, z), for x in l1, for y in l2, for z in l3]

but that's loosing some of it's beauty for me. if we'd use the
semicolon [ x, y, z; for x in l1, for y in l2, for z in l3]
looks better to me.

okay, really heading off to work now,
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter@schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de