[Python-checkins] r66872 - python/trunk/Doc/library/functions.rst

benjamin.peterson python-checkins at python.org
Fri Oct 10 22:51:38 CEST 2008


Author: benjamin.peterson
Date: Fri Oct 10 22:51:37 2008
New Revision: 66872

Log:
talk about how you can unzip with zip

Modified:
   python/trunk/Doc/library/functions.rst

Modified: python/trunk/Doc/library/functions.rst
==============================================================================
--- python/trunk/Doc/library/functions.rst	(original)
+++ python/trunk/Doc/library/functions.rst	Fri Oct 10 22:51:37 2008
@@ -1387,6 +1387,18 @@
    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


More information about the Python-checkins mailing list