Take the 2-minute tour ×

Possible Duplicate:
A Transpose/Unzip Function in Python

I've used the zip() function from the numpy library to sort tuples and now I have a list containing all the tuples. I had since modified that list and now I would like to restore the tuples so I can use my data. How can I do this?

share|improve this question

marked as duplicate by Josh Lee, Benjamin Bannier, ecatmur, Blair, Jon Clements Nov 29 '12 at 22:07


1 Answer 1

up vote 59 down vote accepted
lst1, lst2 = zip(*zipped_list)

should give you the unzipped list.

*zipped_list unpacks the zipped_list object. it then passes all the tuples from the zipped_list object to zip, which just packs them back up as they were when you passed them in.

so if:

a = [1,2,3]
b = [4,5,6]

then zipped_list = zip(a,b) gives you:


and *zipped_list gives you back

(1,4), (2,5), (3,6)

zipping that gives you back the original two lists.

share|improve this answer
