Skip to content

Implement n=1 for .most_common#145895

Closed
Case-y wants to merge 2 commits intopython:mainfrom
Case-y:optimize-most-common-n-equals-1
Closed

Implement n=1 for .most_common#145895
Case-y wants to merge 2 commits intopython:mainfrom
Case-y:optimize-most-common-n-equals-1

Conversation

@Case-y
Copy link

@Case-y Case-y commented Mar 13, 2026

Implement n=1 for .most_common inside of Counter class

Why did I create this?

I wanted to play around with the underlying method with the .most_common. So, I was wondering for the n=1, could we just use max instead of going with a min heap solution? My initial thought for that was, we can use less memory and we can improve run-time as max tends to be a linear operation while heaps can be a performant bottleneck.

Analysis

image

@Case-y Case-y requested a review from rhettinger as a code owner March 13, 2026 01:50
@python-cla-bot
Copy link

python-cla-bot bot commented Mar 13, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Mar 13, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Mar 13, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@Case-y
Copy link
Author

Case-y commented Mar 13, 2026

NVM. Looks like someone else had the same thought process and opened up a PR: #144127

I will close my PR.

@Case-y Case-y closed this Mar 13, 2026
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.

1 participant