[Python-ideas] Allow filter(items)

Shane Green shane at umbrellacode.com
Wed Aug 7 03:55:54 CEST 2013


[item for item in items if item] vs [item for item in items if bool(item)] 

Isn’t an optional predicate function also a very common programming pattern?




On Aug 6, 2013, at 4:47 PM, Terry Reedy <tjreedy at udel.edu> wrote:

> On 8/6/2013 4:23 AM, Serhiy Storchaka wrote:
>> 06.08.13 10:34, Chris Angelico написав(ла):
>>> Okay. Sounds like there's already an answer to those who want more
>>> readability: Just use filter(bool,...). Maybe I'm just not seeing the
>>> obvious problem with this version?
>> 
>> Are `if bool(...)` or `if bool(...) == True` more readable than `if ...`?
> 
> No and irrelevant. This is simply not a parallel situation.
> 
> -- 
> Terry Jan Reedy
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130806/8594d796/attachment.html>


More information about the Python-ideas mailing list