change the stuff to list of tuples
Steven Taschuk
staschuk at telusplanet.net
Tue May 27 01:06:06 EDT 2003
Quoth anson:
> I have three lists:
> [1,2,3]
> ['a','b','c']
> ['d','e','f']
>
> How do I combine the list to become this (in one step if possible)?
>
> [(1,'a','d'),(2,'b','e'), (3,'c','f')]
>>> a = [1, 2, 3]
>>> b = ['a', 'b', 'c']
>>> c = ['d', 'e', 'f']
>>> zip(a, b, c)
[(1, 'a', 'd'), (2, 'b', 'e'), (3, 'c', 'f')]
(That's 'zip' as in 'zipper'.)
Also try
map(None, a, b, c)
Then try both in the case when the lists are of different lengths.
--
Steven Taschuk Aral: "Confusion to the enemy, boy."
staschuk at telusplanet.net Mark: "Turn-about is fair play, sir."
-- _Mirror Dance_, Lois McMaster Bujold
More information about the Python-list
mailing list