This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dennis Sweeney
Recipients Dennis Sweeney, docs@python
Date 2019-05-22.02:09:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I understand that the SequenceMatcher's ratio method does not guarantee that SequenceMatcher(None, a, b).ratio() == SequenceMatcher(None, b, a).ratio(). Below is a counterexample:

    # Example from
    >>> SequenceMatcher(None, 'BRADY', 'BYRD').ratio()
    >>> SequenceMatcher(None, 'BYRD', 'BRADY').ratio()

I was recently solving a problem that required a textual similarity ratio function and I wrongly assumed that SequenceMatcher treated both input strings symmetrically, which was an extremely difficult bug to find, especially because for many simple tests, the ratio IS symmetric:

    >>> SequenceMatcher(None, 'apple', 'banana').ratio()
    >>> SequenceMatcher(None, 'banana', 'apple').ratio()

I would like to see a clearer warning of this asymmetry in the documentation for the difflib module. Perhaps something like

      .. note::

         Caution: The result of a :meth:`ratio` call is *NOT* symmetric with 
         respect to the order of the arguments. For instance::
            >>> SequenceMatcher(None, 'brady', 'byrd').ratio()
            >>> SequenceMatcher(None, 'byrd', 'brady').ratio()

Without such a note near the ratio methods' documentations, it is far too easy to google for a Python stdlib functionality for computing text similarity, skip straight to the ratio method, look at the examples given, try some of your own simple examples, and accidentally convince oneself that this symmetry exists.
Date User Action Args
2019-05-22 02:09:15Dennis Sweeneysetrecipients: + Dennis Sweeney, docs@python
2019-05-22 02:09:15Dennis Sweeneysetmessageid: <>
2019-05-22 02:09:15Dennis Sweeneylinkissue37004 messages
2019-05-22 02:09:15Dennis Sweeneycreate