Snippets

Lilian Besson (Naereen) prod function for Python 2 or 3K (product of the values of an iterator)

You are viewing an old version of this snippet. View the current version.
Revised by Lilian Besson (Naereen) 0c8e573
1
2
3
4
5
6
7
8
def prod(iterator):
    """ Compute the product of the values in the iterator.
    
    - Empty product is 1."""
    p = 1
    for x in iterator:
        p *= x
    return p
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.