[Python-ideas] Provide a 'key' argument for all() and any() builtins
Giampaolo RodolĂ
g.rodola at gmail.com
Mon Jul 23 13:28:08 CEST 2012
More information about the Python-ideas mailing list
Mon Jul 23 13:28:08 CEST 2012
- Previous message: [Python-ideas] Provide a 'key' argument for all() and any() builtins
- Next message: [Python-ideas] Python Package Collections
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2012/7/23 Chris Rebert <pyideas at rebertia.com> > > On Sun, Jul 22, 2012 at 9:03 PM, Giampaolo RodolĂ <g.rodola at gmail.com> wrote: > > This would be similar to 'key' argument already available for min(), max() > > and sorted() and would let user decide what must be considered True and what > > not. > > Some use cases: > > > > > > all(a, b, c, ... key=callable) > > You're missing some brackets or parens there: > all([a, b, c, ...], key=callable) > > <snip> > > Thoughts? > > I see negligible advantage over just writing the generator expression directly: > all(callable(item) for item in iterable) <snip> > min() & max() return the result object satisfying the constraint, so > the `key` argument makes sense for when you want to e.g. find the > cheapest house rather than the price of the cheapest house. > In contrast, any() & all() *always* just return a simple bool result, > not the object whose truthiness determined the predicate's result, so > `key` would be pointless since the result gets converted to a plain > bool anyway (or at least, we can conceptualize the implementation as > if it worked that way). Agreed. Please ignore my proposal then. --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/
- Previous message: [Python-ideas] Provide a 'key' argument for all() and any() builtins
- Next message: [Python-ideas] Python Package Collections
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list