[Tutor] Python Idioms?
Jim Mooney
cybervigilante at gmail.com
Wed Apr 1 06:50:43 CEST 2015
I'm looking at this and can't see how it works, although I understand
zipping and unpacking. The docs say it's a Python idiom. Does "idiom" mean
it works in a special way so I can't figure it out from basic principles?
It looks to me like the iterator in the list gets doubled, so the zip
should make it [(1,1),(2,2),(3,3),... ], not [(1,2),(3,4),...]
What am I missing here?
>>> s = [1,2,3,4,5,6,7,8]
>>> list(zip(*[iter(s)]*2))
>>> [(1, 2), (3, 4), (5, 6), (7, 8)]
https://docs.python.org/3/library/functions.html#zip
--
Jim
More information about the Tutor
mailing list