[Python-3000] Thoughts on collections.Container and collections.Iterable

Raymond Hettinger python at rcn.com
Sat Feb 9 03:31:28 CET 2008


[Nick]
>  does anyone else think a 'key' parameter on any() and all() 
> would be useful?

Not really.  The key= function is useful whenever you need to
keep the original value around for some reason (i.e. sorting
it or getting the min/max value).  But with any() and all()
you don't keep anything.

Also, if you take examples of any() and all() and try them
with the key= syntax, you'll find that they become less readable.

Besides, for the "gurus who are in the know", the min() and max()
functions can often be substituted directly for any() and all()
and then you get the key= syntax for free ;-)

   any(x%2==0 for x in s)
   max(x%2==0 for x in s)

Raymond


More information about the Python-3000 mailing list