A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-December/059197.html below:

[Python-Dev] Small any/all enhancement

[Python-Dev] Small any/all enhancementAlex Martelli aleaxit at gmail.com
Wed Dec 28 16:55:13 CET 2005
On Dec 27, 2005, at 11:06 PM, Eric Nieuwland wrote:
    ...
>>> def zerop(x):
>>>     return x==0
>>>
>>> all(some_objects, zerop)
>>
>> and why would that be better than
>> all(o==0 for o in some_objects)
>> ?
>
> all() can be terminated at the first false element. For very long
> sequences this has important performance benefits. Besides, it makes

Of course it can -- in both formulations.  genexp's are also computed  
"as needed", only one item at a time: you appear to imply they don't,  
maybe you're confusing them with list comprehensions.  What I'm  
asking is, what are the ADVANTAGES of the pred form, that make it  
worth paying the conceptual cost of having "two obvious ways" to do  
one task.

> all(seq,pred) the equivalent of pred(seq[0]) and  pred(seq[1]) and
> pred(seq[2]) and ...

...and also the equivalent of all(pred(s) for s in seq) -- which is  
exactly my problem: I don't like redundant good ways of expressing  
identical tasks.  The genexp will often be more compact, whenever the  
'pred' requires a def, a lambda, or something like  
operator.attrgetter, anyway.

Alex


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4