From: Benjamin Peterson Date: Fri, 10 Oct 2008 20:51:37 +0000 (+0000) Subject: talk about how you can unzip with zip X-Git-Tag: v2.7a1~2746 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83ca0a651130d0894bb6eb1a4196a393f7645626;p=thirdparty%2FPython%2Fcpython.git talk about how you can unzip with zip --- diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 3ed4ab0b364e..f70cc36e69fc 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