Skip to content

difflib.get_close_matches performance #142939

Closed

Description

@dg-pb

Feature or enhancement

Proposal:

  1. s.ratio() is calculated twice
def get_close_matches(...):
    ...
    for x in possibilities:
        s.set_seq1(x)
        if s.real_quick_ratio() >= cutoff and \
           s.quick_ratio() >= cutoff and \
           s.ratio() >= cutoff:
            result.append((s.ratio(), x))
    ...
  1. avail.__contains__ is slower than in operator
    def quick_ration(self):
        ...
        availhas, matches = avail.__contains__, 0
        for elt in self.a:
            if availhas(elt):
                numb = avail[elt]
        ...

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. added
    performancePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directory
    on Dec 18, 2025
  2. added a commit that references this issue on Dec 30, 2025
  3. tim-one commented on Dec 31, 2025

    @tim-one
    Member

    The linked P:R was merged, #142940, so closing this.

  4. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions