Unpacking a list / tuple of pairs into two lists / tuples

Possible Duplicate:
A Transpose/Unzip Function in Python

I have a list that looks like this:

list = (('1','a'),('2','b'),('3','c'),('4','d'))

I want to separate the list in 2 lists.

list1 = ('1','2','3','4')
list2 = ('a','b','c','d')

I can do it for example with:

list1 = []
list2 = []
for i in list:
   list1.append(i[0])
   list2.append(i[1])

But I want to know if there is a more elegant solution.

2 Answers
2

Leave a Comment