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

[Python-Dev] Small any/all enhancement

[Python-Dev] Small any/all enhancement [Python-Dev] Small any/all enhancement"Martin v. Löwis" martin at v.loewis.de
Tue Dec 27 22:49:58 CET 2005
Valentino Volonghi aka Dialtone wrote:
> What I would like to ask, before it's too late, is if it's possible to add an
> optional test argument.

I don't see why: you can easily synthesize that with map/imap.

> These would be the new proposed APIs. The usecase is to be able to extract
> attributes from objects or simply to have arbitrary checks like:
> 
> import operator
> 
> any(some_objects, test=operator.attrgetter('some_attribute'))

So write

  any(map(operator.attrgetter('some_attribute'), some_objects))
  # same number of characters to type

  any(o.some_attribute for o in some_objects)
  # fewer number of characters

> def zerop(x):
>     return x==0
> 
> all(some_objects, zerop)

So write

  all(map(some_objects, zerop))
or
  all(o==0 for o in some_objects)
  # avoids defining zerop

> instead of preprocessing the generator with a generator expression before
> passing it to any/all.

What is the disadvantage of such "preprocessing"?

Regards,
Martin
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