Most efficient unzip - inverse of zip?

Emile van Sebille emile at fenx.com
Tue Mar 26 16:28:08 EST 2002


Pearu Peterson
> What would be the most efficient way to unzip zipped sequences 
> in Python 2.2?
> 
> For example, consider
> 
>  a_b = zip(a,b)  # where a and b are some sequences
>  a_b.sort()
>  a,b = unzip(a_b)
>

You'd need to define efficient better, but I'd try something like:

>>> z = zip(range(52),string.letters)
>>> a = [ii for ii,jj in z]
>>> b = [jj for ii,jj in z]

-- 

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list