merge (Re: zip or marry etc)

Olivier Dagenais olivierS.dagenaisP at canadaA.comM
Wed Jul 19 15:00:40 EDT 2000


> > merge([1, 2, 3], [4, 5, 6]) == [1, 4, 2, 5, 3, 6]
> > or
> > merge([1, 2, 3], [4, 5, 6]) == [(1, 4), (2 ,5), (3, 6)]

Maybe we need two descriptive names for those, like:

interspersed([1, 2, 3], [4, 5, 6]) == [1, 4, 2, 5, 3, 6]

...which could be named something like "zigzag" or "collect", to mean pick
one of the first, one of the second, one of the first, one of the second,
etc...  Maybe we can think of it as two sides of a street, both of which
have houses that have an assigned "address", but traversing the whole
"street", you would see, from looking left, then right (and repeating), the
sequence of house numbers [1, 4, 2, 5, 3, 6], whereas looking on only the
left side would yield [1, 2, 3]...


and

paired_up([1, 2, 3], [4, 5, 6]) == [(1, 4), (2 ,5), (3, 6)]

...which could be named something like "rungs" or "ladder", if you think of
the input as:
1            4
2    and     5
3            6

and the output as

1 ---------- 4
2 ---------- 5
3 ---------- 6

...that looks like rungs or a ladder, no?  Or like a "Zipper" (tm), although
"zip" is too often associated with compressed archives, like Bjorn points
out...  (Isn't a DNA strand like a "twisted" ladder?)

--
----------------------------------------------------------------------
Olivier A. Dagenais - Carleton University - Computer Science III


"Bjorn Pettersen" wrote in message news:3975EF36.1651C9CB at roguewave.com...
> Peter Schneider-Kamp wrote:
> >
> > Okay, assume you call it "merge". What will somebody who
> > doesn't know what it's for think it does?
> >
> > merge([1, 2, 3], [4, 5, 6]) == [1, 4, 2, 5, 3, 6]
> >
> > or
> >
> > merge([1, 2, 3], [4, 5, 6]) == [(1, 4), (2 ,5), (3, 6)]?
>
> Point taken.
>
> > Where's your problem with zip?
>
> Not a problem really, although my first association was "why would we
> want to iterate over a compressed sequence..." <wink>
>
> -- bjorn
>





More information about the Python-list mailing list