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/059161.html below:

[Python-Dev] Small any/all enhancement

[Python-Dev] Small any/all enhancement [Python-Dev] Small any/all enhancementEric Nieuwland eric.nieuwland at xs4all.nl
Wed Dec 28 08:06:09 CET 2005
Alex Martelli wrote:
> On Dec 27, 2005, at 12:45 PM, Valentino Volonghi aka Dialtone wrote:
>     ...
>> any(iterable, test=bool) and all(iterable, test=bool)
>     ...
>> any(some_objects, test=operator.attrgetter('some_attribute'))
>
> Why would that be better than
> any(o.some_attribute for o in some_objects)
> ?
>
>> 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 
all(seq,pred) the equivalent of pred(seq[0]) and  pred(seq[1]) and 
pred(seq[2]) and ...

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