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 6928447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:11:22+00:00 2026-05-27T11:11:22+00:00

The documentation for the built-in functions max and min in Python indicate that the

  • 0

The documentation for the built-in functions max and min in Python indicate that the key parameter should operate like it does in the sort function. In other words, I should be able to do this:

a = [1, 2, 3, 4]
max(a, key=None)

However, this raises an error:
TypeError: 'NoneType' object is not callable

But, if I do something similar with the sort function, I get the expected results:

a = [1, 2, 3, 4]
a.sort(key=None)

No error is generated and the default sort is used. Several books also imply that I should be able to get away with the same behavior in the max and min functions. See this excerpt from Python in a Nutshell.

Is this really the default behavior of the max and min functions? Should it be? Shouldn’t they match the sort function?

  • 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-05-27T11:11:23+00:00Added an answer on May 27, 2026 at 11:11 am

    You’ve stumbled on to a difference in the implementation of .sort and max more than a problem with the language.

    list.sort() takes a keyword argument “key” which happens to default to None. This means that the sort method can’t tell the difference between you supplying a key=None argument or it just taking on the default value. In either case, it behaves as if no key function has been provided.

    max on the other hand is checking for the presence of a keyword argument “key”. It does not have a default value and it’s value is used as the key function if present at all.

    Either way, key should never be supplied as None. It is supposed to be a function which is used to extract a “key” value from the items in the list/iterable. For instance:

    a = [("one", 1), ("two", 2), ("three", 3), ("four", 4)]
    a.sort(key=lambda item:item[1])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own db class which has some purpose built functions that I
The CORE documentation has shown me how to merrily mock various built Perl functions.
In python documentation it is wrote for built-in function complex([real[imag]]): ..or convert a string
I like a lot of what I've read about D. Unified Documentation (That would
Is there any documentation on how Python's string functions are implemented in Python? I
The documentation about List mention that itemTpl follows the XTemplate syntax. I would like
The Overriding Built-in Functions section of the perlsub documentation provides There is a second
Our company publishes our software product's documentation using a custom-built content management system using
I would like to build some smaller scale but hightly customized documentation sites for
Documentation simply states that setting setAutosavingDelay to anything > 0 on the shared doc

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.