Snippets

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

Created by Lilian Besson (Naereen) last modified
def prod(iterator):
    """ Compute the product of the values in the iterator.
    
    - Empty product is 1.
    - Code compatible with Python 2 and 3 (2.6 or higher)
    """
    p = 1
    for x in iterator:
        p *= x
    return p

Comments (1)