GeezerVison is showing github.com — implementation of the `minmax` function by Marius-Juston · Pull Request #144382 · python/cpython
Conversation
The minmax function implementation
This pull request implements the minmax function, which is very similar to the min and max functions; however, makes it much more efficient to compute both the min and the max values in a single pass. This is extremely useful for a lot of applications, for example it can be used inside the textwrap.dedent (#131919 ) function inside Python, the min and max functions are also very often used inside statical methods to compute the range of values.
The advantage of this system is that instead of doing 2 passes inside the dataset / iterable, it can be once.
The function would be defined as:
(min_val, max_val) = minmax([1,2,34,45,6])
This probably needs a PEP (I am just familiar enough with the process so I am putting Pull request first)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Also inside the min_max function that is already defined it would probably make it more readable if:
(line 2044 of bltinmodule.c)
if (cmp < 0)
goto Fail_it_item_and_val;
and
(line 2067 of bltinmodule.c)
used brackets as,
(line 2044 of bltinmodule.c)
if (cmp < 0) {
goto Fail_it_item_and_val;
}
and
(line 2067 of bltinmodule.c)
else {
Py_DECREF(maxval);
}
I can add this to my pull request if we want as well.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
It might not necessary make complete sense for this function to be part of the builtin since it's functionality is so close to min and max and maybe it should be moved to the math portion of the library instead or something?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
picnixz
commented
Feb 1, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Please do not create PRs for features without a discussion. This is not the way contribution works here. The workflow is explained in the devguide which was referenced in this repo's README.
|
Marius-Juston and tim-one reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
ericsnowcurrently
Awaiting requested review from ericsnowcurrently
ericsnowcurrently is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.