Re: best cumulative sum




"Peter Otten" <__peter__@xxxxxx> wrote in message
news:dm2b8b$p8n$02$1@xxxxxxxxxxxxxxxxxxxx
> You are in for a surprise here:

You got that right!

> >>> def empty():
> ... for item in []:
> ... yield item
> ...
> >>> bool(empty())
> True

Ouch.

> >>> bool(iter([]))
> True # python 2.3 and probably 2.5
>
> >>> bool(iter([]))
> False # python 2.4

Double ouch.
I was relying on Python 2.4 behavior.
What is the reasoning behind the changes?
(Can you offer a URL to a discussion?)

So, is the only way to test for an empty iterable
to see if it can generate an item? I found this:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413614
Seems like a reason to rely on sequences ...

Thanks,
Alan Isaac


.