i trying reduce in python , getting 0 when expecting other values:
in [1]: functools import reduce in [2]: reduce( (lambda x, y: x * y), [1, 2, 3, 4] ) out[2]: 24 in [3]: def multiply(x, y): return x * y in [4]: reduce( multiply, [1, 2, 3, 4] ) out[4]: 24 in [5]: reduce( multiply, range(5) ) out[5]: 0 in [6]: reduce( multiply, list(range(5)) ) out[6]: 0 [...] in [11]: l = list(range(5)) in [12]: l out[12]: [0, 1, 2, 3, 4] in [13]: reduce(multiply, l) out[13]: 0
why getting 0 when not entering literal list? how can reduce arbitrary lists? missing?
python's range
starts 0
, not 1
. 0
times causes 0
you're getting...
Comments
Post a Comment