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/2003-October/039510.html below:

[Python-Dev] product()

[Python-Dev] product() [Python-Dev] product()Guido van Rossum guido at python.org
Sat Oct 25 17:14:32 EDT 2003
> it might be "alltrue" and "anytrue" -- the short-circuiting ones,
> returning the first true or false item found respectively, as in:
> 
> def alltrue(seq):
>     for x in seq:
>         if not x: return x
>     else:
>         return True
> 
> def anytrue(seq):
>     for x in seq:
>         if x: return x
>     else:
>         return False
> 
> these seem MUCH more generally useful than 'product' (but,
> I still opine, not quite enough to warrant being built-ins).

These are close to what ABC does with quantifiers.  There, you can
write

  IF EACH x IN sequence HAS x > 0: ...

ABC has the additional quirk that if there's an ELSE branch, you can
use x in it (as a "counter-example").

In Python, you could write this as

  if alltrue(x > 0 for x in sequence): ...

but the current design doesn't expose x to the else branch.

--Guido van Rossum (home page: http://www.python.org/~guido/)

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