GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — implementation of the `minmax` function by Marius-Juston · Pull Request #144382 · python/cpython

Conversation

@Marius-Juston

@Marius-Juston Marius-Juston commented Feb 1, 2026

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Marius-Juston
implementation of the minmax function
805a332
@Marius-Juston
Marius-Juston requested a review from ericsnowcurrently as a code owner February 1, 2026 21:30
@bedevere-app bedevere-app Bot added the awaiting review label Feb 1, 2026
Marius-Juston added 3 commits February 1, 2026 15:31
@Marius-Juston
added documentation and blurb
76690ae
@Marius-Juston
used double backticks for inline literals
d85c9f5
@Marius-Juston
updated indent and function highlighting
5292039
@Marius-Juston

Marius-Juston commented Feb 1, 2026

Copy link
Copy Markdown
Contributor Author

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)

else
    Py_DECREF(maxval);

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Marius-Juston

Marius-Juston commented Feb 1, 2026

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz closed this Feb 1, 2026
@picnixz

picnixz commented Feb 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@ericsnowcurrently 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

Labels

awaiting review

Projects

None yet

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.

2 participants

@Marius-Juston @picnixz
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.