A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-March/052014.html below:

[Python-Dev] Adding any() and all()

[Python-Dev] Adding any() and all()Phillip J. Eby pje at telecommunity.com
Fri Mar 11 04:05:02 CET 2005
At 06:38 PM 3/10/05 -0800, Bill Janssen wrote:
>Guido,
>
>I think there should be a PEP.  For instance, I think I'd want them to be:
>
>def any(S):
>   for x in S:
>     if x:
>       return x
>   return S[-1]
>
>def all(S):
>   for x in S:
>     if not x:
>       return x
>   return S[-1]
>
>Or perhaps these should be called "first" and "last".

More precisely (since "S" might be an iterator, or empty):

def any(S):
     x = False
     for x in S:
         if x: break
     return x

def all(S):
     x = True
     for x in S:
         if not x: break
     return x

However, "first" and "last" don't make sense to me as names.  First 
what?   Last what?  Actually, "any" and "all" don't make that much sense to 
me either.  I find myself wanting to call them "or" and "and", or maybe 
"or_iter" and "and_iter".  Or perhaps "until_false" or "until_true".  Nah, 
the and/or names make more sense, as they exactly match the behavior of the 
corresponding logical operators, if you could call them as a function.  At 
least, if they took *args anyway.


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