Three dumb questions (ordered by dumbness descending)
Mark McEahern
marklists at mceahern.com
Mon Sep 23 22:11:39 EDT 2002
[Steven Feil]
> Humm, what is is zip()[...]
Steven, meet zip. <wink>
$ python
Python 2.2.1 (#1, Jun 25 2002, 10:55:46)
[GCC 2.95.3-5 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print zip.__doc__
zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]
Return a list of tuples, where each tuple contains the i-th element
from each of the argument sequences. The returned list is truncated
in length to the length of the shortest argument sequence.
>>> l = range(10)
>>> zip(l, l)
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9,
9)]
>>> d = dict(zip(l, l))
>>> d
{0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9}
>>>
Neato, huh?
Cheers,
// m
-
More information about the Python-list
mailing list