implementation of the `minmax` function by Marius-Juston · Pull Request #144382 · python/cpython · GitHub
Skip to content

implementation of the minmax function - #144382

Closed
Marius-Juston wants to merge 4 commits into
python:mainfrom
Marius-Juston:minmax
Closed

Marius-Juston wants to merge 4 commits into
python:mainfrom
Marius-Juston:minmax

Conversation

@Marius-Juston

Copy link
Copy Markdown
Contributor

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)

@Marius-Juston

Copy link
Copy Markdown
Contributor Author

@Marius-Juston

Copy link
Copy Markdown
Contributor Author

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?

@picnixz picnixz closed this Feb 1, 2026
@picnixz

picnixz commented Feb 1, 2026

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants