On Sun, Apr 4, 2010 at 7:46 PM, monkeys paw <mon...@joemoney.net> wrote:
> Why does the following fail with the Traceback?
>
> def add(x,y): return x+y
> for rrr in range(1,20):
>        reduce(add, range(1, r))
>
> Traceback (most recent call last):
>  File "<interactive input>", line 2, in <module>
> TypeError: reduce() of empty sequence with no initial value
> --

>>> for x in range(1,1) :
...    print x
...
>>>

ranges start at the first value and go up to, but not including, the
second value. So range(1,1) gives you no values. reduce doesn't know
what to do with an empty sequence, so it throws an error.

> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to