[Python-Dev] PEP 201 - Parallel iteration

Barry A. Warsaw bwarsaw@beopen.com
Tue, 18 Jul 2000 23:58:28 -0400 (EDT)


>>>>> "KM" == Ken Manheimer <klm@digicool.com> writes:

    KM> Evan Simpson (a colleague here at digicool, who'd be a good
    KM> addition to python-dev) noticed that unzip is unnecessary -
    KM> zip is its own inverse.

Only if the sequences are of the same length.  I've added this to the
PEP, using the extended call syntax.

    Note that when the sequences are of the same length, zip() is
    reversible:

    >>> a = (1, 2, 3)
    >>> b = (4, 5, 6)
    >>> x = zip(a, b)
    >>> y = zip(*x) # alternatively, apply(zip, x)
    >>> z = zip(*y) # alternatively, apply(zip, y)
    >>> x
    [(1, 4), (2, 5), (3, 6)]
    >>> y
    [(1, 2, 3), (4, 5, 6)]
    >>> z
    [(1, 4), (2, 5), (3, 6)]
    >>> x == z
    1

    It is not possible to reverse zip this way when the sequences are
    not all the same length.

-Barry