Skip to content

Instantly share code, notes, and snippets.

@k0001
Created September 26, 2010 23:17
Show Gist options
  • Save k0001/598404 to your computer and use it in GitHub Desktop.
Save k0001/598404 to your computer and use it in GitHub Desktop.
>>> from itertools import izip
>>>
>>> def izip_op(op=tuple, *lists):
... return (op(x) for x in izip(*lists))
...
...
...
>>> list(izip_op(sum, [1,2,3], [4,5,6]))
[5, 7, 9]
>>> list(izip_op(lambda x: reduce(operator.mul, x), [1,2,3], [4,5,6]))
[4, 10, 18]
>>> list(izip_op(lambda x: reduce(operator.mul, x), [1,2,3], [4,5,6], [7,8,9]))
[28, 80, 162]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment