Created
April 13, 2016 15:44
-
-
Save nedbat/f09c9767067e4b5c3bca01e369d1a4d7 to your computer and use it in GitHub Desktop.
Demonstration of zip being its own inverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 3.5.1 (default, Dec 7 2015, 06:25:20) | |
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> a = list(range(5)) | |
>>> b = list(range(100, 105)) | |
>>> a | |
[0, 1, 2, 3, 4] | |
>>> b | |
[100, 101, 102, 103, 104] | |
>>> ab = list(zip(a, b)) | |
>>> ab | |
[(0, 100), (1, 101), (2, 102), (3, 103), (4, 104)] | |
>>> a, b = zip(*ab) | |
>>> a | |
(0, 1, 2, 3, 4) | |
>>> b | |
(100, 101, 102, 103, 104) | |
>>> | |
>>> abt = list(zip(*ab)) | |
>>> abt | |
[(0, 1, 2, 3, 4), (100, 101, 102, 103, 104)] | |
>>> ab2 = list(zip(*abt)) | |
>>> ab2 | |
[(0, 100), (1, 101), (2, 102), (3, 103), (4, 104)] | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment