[Python-ideas] Allow filter(items)

Shane Green shane at umbrellacode.com
Wed Aug 7 23:43:47 CEST 2013


On Aug 7, 2013, at 10:20 AM, Terry Reedy <tjreedy at udel.edu> wrote:

> On 8/7/2013 4:55 AM, Serhiy Storchaka wrote:
> 
>> The default predicate is not "bool". The default is identity function
>> (lambda x: x).
> 
> Not really. None means "do not apply *any* predicate function".
> 
> -- 
> Terry Jan Reedy
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

Which is the identity function predicate and not bool. 

Wrriten as [item for item in items if predicate(item)]

None translates: 
  [item for item in items if predicate(item)] 
     — into —  
  [item for item in items if item] 
        — not  — 
  [item for item in items if bool(item)]

So predicate is defined such that predicate(item) == item, which is the definition of the identity function, not bool.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130807/672dd977/attachment-0001.html>


More information about the Python-ideas mailing list