A really bad idea.

Terry Reedy tjreedy at udel.edu
Fri Nov 15 12:56:09 EST 2002


"Paul Foley" <see at below.invalid> wrote in message
news:m2of8rgg5j.fsf at mycroft.actrix.gen.nz...
> >>>> a = [(1,2,3,4),(5,6,7,8)]
> >>>> zip(zip(a))
> > [(((1, 2, 3, 4),),), (((5, 6, 7, 8),),)]
>
> How did you get that?  I get
>
>   >>> a = [(1,2,3,4),(5,6,7,8)]
>   >>> zip(a)
>   [(1, 2, 3, 4), (5, 6, 7, 8)]

On what system/build?  Cutting and pasting your entered data...

Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [(1,2,3,4),(5,6,7,8)]
>>> zip(a)
[((1, 2, 3, 4),), ((5, 6, 7, 8),)]
>>> zip(*a)
[(1, 5), (2, 6), (3, 7), (4, 8)]

TJR



>
> and, not surprisingly,
>
>   >>> zip(zip(a))
>   [(1, 2, 3, 4), (5, 6, 7, 8)]
>
> so it works there.  And now
>
>   >>> b = zip(*a)
>   >>> b
>   [(1, 5), (2, 6), (3, 7), (4, 8)]
>
> and
>
>   >>> c = zip(*b)
>   >>> c
>   [(1, 2, 3, 4), (5, 6, 7, 8)]
>
> and
>
>   >>> c == a
>   1
>
>
>
> Oh, I see; I wrote a zip function in my startup file before it was a
> builtin, and I've never taken it out...the builtin version does as
you
> say in the first example (but why?  Looks like a bug, to me!)
>
> --
> Whenever you find that you are on the side of the majority, it is
time
> to reform.                                                  -- Mark
Twain
>
> (setq reply-to
>   (concatenate 'string "Paul Foley " "<mycroft" '(#\@)
"actrix.gen.nz>"))





More information about the Python-list mailing list