[Tutor] Is this a job for zip(), or some other way?

Bob Gailer bgailer at alum.rpi.edu
Thu Mar 25 19:16:18 EST 2004


At 04:58 PM 3/25/2004, R. Alan Monroe wrote:

>Given:
>[ ('bob', 24, 457), ('mike', 20, 4567), ('steve', 30, 576), ....
>arbitrary n number of tuples in this list]
>
>I want to return:
>[ ['bob', 'mike', 'steve',... up to n elements],
>   [24, 20, 30, .... n],
>   [457, 4567, 576, .... n] ]
>
>
>I played around with zip and list comprehensions but I was too burnt
>out to get it, today. Any ideas?

 >>> apply(zip, [ ('bob', 24, 457), ('mike', 20, 4567), ('steve', 30, 576)])
[('bob', 'mike', 'steve'), (24, 20, 30), (457, 4567, 576)]

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 




More information about the Tutor mailing list