Should any() and all() take a key= argument?

Paul Rubin http
Sat Apr 1 22:09:24 EST 2006


Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> >> any(map(lambda x: x==42, lst))
> ...
> In any case, I question your assumption that the version using map must
> automatically "waste memory". 

There's also always itertools.imap.

> But then, unless these are big complex objects, why are we
> micro-optimizing our code anyway? I'm running a Python process, and
> it is consuming 6.7MB of memory at the moment. Do I really care about
> saving 80 or 100 bytes?, or even 100 kilobytes? I don't think so.

The idea is to write code to be assumption-free when possible.  A
general purpose library function should work efficiently on big
complex objects even if some specific application might use it only
for small objects.  Similarly, application programs that will stay in
use for a while should be written to be able to handle large workloads
even if the initial requirements are small, unless significant extra
development effort is needed.



More information about the Python-list mailing list