Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
Created October 13, 2011 20:24
Show Gist options
  • Save pyrtsa/1285407 to your computer and use it in GitHub Desktop.
Save pyrtsa/1285407 to your computer and use it in GitHub Desktop.
prod(iterable)
def prod(iterable):
"""Multiply elements of the iterable from left to right"""
import operator
end, it = object(), iter(iterable)
first = next(it, end)
return reduce(operator.mul, it, first) if first is not end else 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment