Ignore:
Timestamp:
21 Oct 2012, 10:43:54 (12 years ago)
Author:
uli
Message:

Add a helper to provide a (Python 3 compatible) product calculator for sequences of numbers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py

    r9043 r9372  
    685685        writer.writerow(row)
    686686    return tmp_path
     687
     688def product(sequence, start=1):
     689    """Returns the product of a sequence of numbers (_not_ strings)
     690    multiplied by the parameter `start` (defaults to 1). If the
     691    sequence is empty, returns 0.
     692    """
     693    if not len(sequence):
     694        return 0
     695    result = start
     696    for item in sequence:
     697        result *= item
     698    return result
Note: See TracChangeset for help on using the changeset viewer.