merge (Re: zip or marry etc)

Bernhard Herzog herzog at online.de
Thu Jul 20 10:57:07 EDT 2000


Peter Schneider-Kamp <peter at schneider-kamp.de> writes:

> If there wasn't this cross product connotation problem I'd really
> prefer the syntactic sugar:
> 
> for x,y; y in [(1,2), (3,4)]; [5, 6]

Could it be you meant

    for x; y in [(1,2), (3,4)]; [5, 6]:

? That's the version you used in your questionnaire.

This may habe been proposed before, but how about || as in

   for x, y in sequence1 || sequence2:
	pass

sequence1 || sequence2 would be equivalent to zip(sequence1, sequence2).

I think || conveys the notion of parallel iteration nicely. The main
disadvantage is that Python newbies coming from e.g. C or Perl will
confuse it with the logical or operator at first.

The zip() builtin has the advantage that you can influence its behavior
with extra keyword arguments like pad.

-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list