This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add new function or method to return the dict key with the maximum value
Type: enhancement Stage: resolved
Components: Versions: Python 3.11
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, mablue, steven.daprano
Priority: normal Keywords:

Created on 2021-12-05 17:37 by mablue, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg407719 - (view) Author: Masoud Azizi (mablue) Date: 2021-12-05 17:37
Maximum_signal_key=max(collective_signals,key=collective_signals.get)
This code is really hard to learn and remember.
Please change it to something that more sense.
msg407723 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-12-05 17:53
The code makes perfect sense. If you want to find the maximum key in a dict, you write:

    max(collective_signals)

If you want to find the maximum key according to some key function, you write:

    max(collective_signals, key=function)


If you want to find the maximum key according to its associated value, the key function that will work is collective_signals.get. That makes perfect sense.

Not every one-line piece of code needs to be a builtin function.

In any case, Python 3.6 to 3.10 are all in feature-freeze. Even if we added some special function to do this, which I doubt we will do, it could only go into 3.11.
msg407726 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-12-05 18:44
I agree that we don't need a special function for this, so I'm going to close this.
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90147
2021-12-05 18:44:45eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg407726

resolution: rejected
stage: resolved
2021-12-05 17:54:14steven.dapranosettitle: Getting key of max value of dict really dose not sense -> Add new function or method to return the dict key with the maximum value
2021-12-05 17:53:00steven.dapranosetnosy: + steven.daprano

messages: + msg407723
versions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
2021-12-05 17:37:28mabluecreate