Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7819057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:47:10+00:00 2026-06-02T06:47:10+00:00

and and or return the last element they evaluated, but why doesn’t Python’s built-in

  • 0

and and or return the last element they evaluated, but why doesn’t Python’s built-in function any?

I mean it’s pretty easy to implement oneself like this, but I’m still left wondering why.

def any(l):
    for x in l:
        if x:
            return x
    return x

edit:

To add to the answers below, here’s an actual quote from that same mailing list of ye mighty emperor on the issue:

Whether to always return True and False or the first faling / passing
element? I played with that too before blogging, and realized that the
end case (if the sequence is empty or if all elements fail the test)
can never be made to work satisfactory: picking None feels weird if
the argument is an iterable of bools, and picking False feels weird if
the argument is an iterable of non-bool objects.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:47:12+00:00Added an answer on June 2, 2026 at 6:47 am

    This very issue came up up on the Python developer’s mailing list in 2005, when Guido Van Rossum proposed adding any and all to Python 2.5.

    Bill Janssen requested that they be implemented as

    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]
    

    Raymond Hettinger, who implemented any and all, responded specifically addressing why any and all don’t act like and and or:

    Over time, I’ve gotten feedback about these and other itertools recipes.
    No one has objected to the True/False return values in those recipes or
    in Guido’s version.

    Guido’s version matches the normal expectation of any/all being a
    predicate. Also, it avoids the kind of errors/confusion that people
    currently experience with Python’s unique implementation of “and” and
    “or”.

    Returning the last element is not evil; it’s just weird, unexpected, and
    non-obvious. Resist the urge to get tricky with this one.

    The mailing list largely concurred, leaving the implementation as you see it today.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

return false seems to work in the submitHandler but I'm not sure why. function
i got this code working and it to return the last tweet from my
Running a query which should return all open questions along with the last update
I'm trying to create linq lambda expression to return customer whose first or last
How can I check if this key is the last element in an array?
I'm having an issue whereby I navigate around my site but when I return
public static string GetCurrentEmployeeName() { return db.Employees.SingleOrDefault( c => c.NTUserName == CurrentUsername() ).Last_First; }
return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(c => c .Database(Database) .TrustedConnection() .Server(Server) ).ShowSql()) .ExposeConfiguration(c => c.SetProperty(current_session_context_class, web))
Return Successful Dim user = ravi Dim pass = admin objcmd.CommandText = Select *
return false; for form submission is working for the rest of my code, just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.