Created
September 26, 2010 23:17
-
-
Save k0001/598404 to your computer and use it in GitHub Desktop.
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
>>> 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