[Tutor] Is this a job for zip(), or some other way?
Gregor Lingl
glingl at aon.at
Thu Mar 25 20:16:21 EST 2004
Bob Gailer schrieb:
> ....
> >>> apply(zip, [ ('bob', 24, 457), ('mike', 20, 4567), ('steve', 30,
> 576)])
> [('bob', 'mike', 'steve'), (24, 20, 30), (457, 4567, 576)]
>
>
This works also:
>>> zip(('bob', 24, 457), ('mike', 20, 4567), ('steve', 30, 576))
[('bob', 'mike', 'steve'), (24, 20, 30), (457, 4567, 576)]
So in your case
>>> zip(*[ ('bob', 24, 457), ('mike', 20, 4567), ('steve', 30, 576)])
[('bob', 'mike', 'steve'), (24, 20, 30), (457, 4567, 576)]
would also be appropriate.
Gregor
P.S.:
*zip*( seq1, ...)
This function returns a list of tuples, where the i-th tuple
contains the i-th element from each of the argument sequences. At
least one sequence is required, otherwise a TypeError is raised. The
returned list is truncated in length to the length of the shortest
argument sequence. When there are multiple argument sequences which
are all of the same length, zip() is similar to map() with an
initial argument of |None|. With a single sequence argument, it
returns a list of 1-tuples. New in version 2.0.
More information about the Tutor
mailing list