FAQ
from itertools import ifilter


if all (hasattr (b, 'test') for b in ifilter (lambda b: b < 10, [1,2,3,4])):
     print 'True'


same result using filter instead of ifilter.


hasattr (b, 'test') where b is 1, 2, 3... should all be False. So why does
this print True?


--
Those who fail to understand recursion are doomed to repeat it

Search Discussions

  • Neal Becker at May 11, 2015 at 12:58 pm
    Nevermind - I found the answer. I was trying this in ipython with pylab:


    http://stackoverflow.com/questions/7491951/python-builtin-all-with-generators


    Neal Becker wrote:

    from itertools import ifilter

    if all (hasattr (b, 'test') for b in ifilter (lambda b: b < 10,
    [1,2,3,4])):
    print 'True'

    same result using filter instead of ifilter.

    hasattr (b, 'test') where b is 1, 2, 3... should all be False. So why
    does this print True?
    --
    Those who fail to understand recursion are doomed to repeat it

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 11, '15 at 12:51p
activeMay 11, '15 at 12:58p
posts2
users1
websitepython.org

1 user in discussion

Neal Becker: 2 posts

People

Translate

site design / logo © 2018 Grokbase