Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   bool evaluations of generators vs lists (http://www.velocityreviews.com/forums/t669867-bool-evaluations-of-generators-vs-lists.html)

Josh Dukes 02-10-2009 07:15 PM

bool evaluations of generators vs lists
 
quite simply...what???

In [108]: bool([ x for x in range(10) if False ])
Out[108]: False

In [109]: bool( x for x in range(10) if False )
Out[109]: True

Why do these two evaluate differently? I was expecting that they would
evaluate the same but the generator would return true *as soon as the
first value is detected*. I'd really expect it to act more like...

def has_values(g):
for i in g:
return True
return False

So what's going on here? Am I using the wrong function or is this
actually just a bug?

--

Josh Dukes
MicroVu IT Department


All times are GMT. The time now is 11:15 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.