From 83ca0a651130d0894bb6eb1a4196a393f7645626 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 10 Oct 2008 20:51:37 +0000 Subject: talk about how you can unzip with zip --- Doc/library/functions.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 -- cgit v0.12