How do I sort these?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Fri Oct 28 19:58:16 EDT 2005


On Fri, 28 Oct 2005 13:42:49 -0700, KraftDiner wrote:

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

Nor for me:

>>> unzip
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'unzip' is not defined


I don't think it exists.

But it is easy enough to create:

def unzip(L):
    """Reverse a zip.

    Expects L to be a list of the form:
        [(1, 'a'), (2, 'b'), (3, 'c')]
    and returns:
        [(1, 2, 3), ('a', 'b', 'c')]

    Note that unzip(zip(seq1, seq2)) is not quite a null-op, 
    because some type information is lost, e.g. lists and 
    strings are converted into tuples.
    """
    return zip(*L)

As you can see, the documentation for unzip is longer than the code itself :-)



-- 
Steven.




More information about the Python-list mailing list