best cumulative sum
David Isaac
aisaac0 at verizon.net
Wed Nov 23 21:56:10 EST 2005
"Peter Otten" <__peter__ at web.de> wrote in message
news:dm2b8b$p8n$02$1 at news.t-online.com...
> 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
More information about the Python-list
mailing list