]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
talk about how you can unzip with zip
authorBenjamin Peterson <benjamin@python.org>
Fri, 10 Oct 2008 20:51:37 +0000 (20:51 +0000)
committerBenjamin Peterson <benjamin@python.org>
Fri, 10 Oct 2008 20:51:37 +0000 (20:51 +0000)
Doc/library/functions.rst

index 3ed4ab0b364e178493b069b57d04910e9beeee88..f70cc36e69fc2fe9159eecdeee61592046dd91ac 100644 (file)
@@ -1387,6 +1387,18 @@ available.  They are listed here in alphabetical order.
    makes possible an idiom for clustering a data series into n-length groups
    using ``zip(*[iter(s)]*n)``.
 
+   :func:`zip` in conjunction with the ``*`` operator can be used to unzip a
+   list::
+
+      >>> x = [1, 2, 3]
+      >>> y = [4, 5, 6]
+      >>> zipped = zip(x, y)
+      >>> zipped
+      [(1, 4), (2, 5), (3, 6)]
+      >>> x2, y2 = zip(*zipped)
+      >>> x == x2, y == y2
+      True
+
    .. versionadded:: 2.0
 
    .. versionchanged:: 2.4