How do I sort these?

Sam Pointon free.condiments at gmail.com
Fri Oct 28 17:06:27 EDT 2005


> unzip doesn't seem to work for me...

It's not a part of the standard Python distribution, but this is a
naive implementation (it doesn't react well to the list's contents
having different lengths).

def unzip(seq):
    result = [[] for i in range(len(seq[0]))]
    for item in seq:
        for index in range(len(item)):
            result[index].append(item[index])
    return result

>>> unzip(zip(range(5), 'abcde'))
[[0, 1, 2, 3, 4], ['a', 'b', 'c', 'd', 'e']]




More information about the Python-list mailing list