Re: best cumulative sum
- From: "David Isaac" <aisaac0@xxxxxxxxxxx>
- Date: Thu, 24 Nov 2005 02:56:10 GMT
"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
.
- Follow-Ups:
- Re: best cumulative sum
- From: Peter Otten
- Re: best cumulative sum
- References:
- best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Micah Elliott
- Re: best cumulative sum
- From: Erik Max Francis
- Re: best cumulative sum
- From: bonono@xxxxxxxxx
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Colin J. Williams
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Michael Spencer
- Re: best cumulative sum
- From: bonono@xxxxxxxxx
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Peter Otten
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Peter Otten
- best cumulative sum
- Prev by Date: Re: Making immutable instances
- Next by Date: Re: Python as Guido Intended
- Previous by thread: Re: best cumulative sum
- Next by thread: Re: best cumulative sum
- Index(es):