surprising result all (generator) (bug??)

Tim Chase python.list at tim.thechases.com
Tue Jan 31 07:49:26 EST 2012


On 01/31/12 06:40, Neal Becker wrote:
> I was just bitten by this unexpected behavior:
>
> In [24]: all ([i>  0 for i in xrange (10)])
> Out[24]: False
>
> In [25]: all (i>  0 for i in xrange (10))
> Out[25]: True

You sure you transcribed that correctly?

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
 >>> all([i>0 for i in xrange(10)])
False
 >>> all(iter([i>0 for i in xrange(10)]))
False
 >>> all(i>0 for i in xrange(10))
False


So unless it's something in a newer version of Python, I suspect 
your examples aren't what you typed.

-tkc





More information about the Python-list mailing list