summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-10-10 20:51:37 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-10-10 20:51:37 (GMT)
commit83ca0a651130d0894bb6eb1a4196a393f7645626 (patch)
tree0097e4a3fc1a06867591bdbda87f8e3f12d56f80 /Doc/library
parentcae5848f12ae118aecf61101f72219cc8a87e2be (diff)
downloadcpython-83ca0a651130d0894bb6eb1a4196a393f7645626.zip
cpython-83ca0a651130d0894bb6eb1a4196a393f7645626.tar.gz
cpython-83ca0a651130d0894bb6eb1a4196a393f7645626.tar.bz2
talk about how you can unzip with zip
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/functions.rst12
1 files changed, 12 insertions, 0 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 3ed4ab0..f70cc36 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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