1.1 --- a/lib/__builtins__/iterable.py Wed Nov 30 18:41:04 2016 +0100
1.2 +++ b/lib/__builtins__/iterable.py Wed Nov 30 18:41:59 2016 +0100
1.3 @@ -69,6 +69,32 @@
1.4 def reversed(sequence): pass
1.5 def sorted(iterable, cmp=None, key=None, reverse=False): pass
1.6 def sum(sequence, start=0): pass
1.7 -def zip(*args): pass
1.8 +
1.9 +def zip(args):
1.10 +
1.11 + """
1.12 + Zip the given 'args' together, producing for each index position tuples
1.13 + containing the values for that position from each of the 'args'.
1.14 + """
1.15 +
1.16 + result = []
1.17 + pos = 0
1.18 +
1.19 + # Repeat until one of the arguments runs out of elements.
1.20 +
1.21 + while True:
1.22 + l = []
1.23 +
1.24 + # Visit each argument in turn, collecting elements in the given
1.25 + # position.
1.26 +
1.27 + for arg in args:
1.28 + try:
1.29 + l.append(arg[pos])
1.30 + except IndexError:
1.31 + return result
1.32 +
1.33 + result.append(tuple(l))
1.34 + pos += 1
1.35
1.36 # vim: tabstop=4 expandtab shiftwidth=4