Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>isjunk</code> works a little differently than you might think. In general, <code>isjunk</code> merely identifies one or more characters that do not affect the length of a match but that are still included in the total character count. For example, consider the following:</p> <pre><code>&gt;&gt;&gt; SequenceMatcher(lambda x: x in "abcd", " abcd", "abcd abcd").ratio() 0.7142857142857143 </code></pre> <p>The first four characters of the second string (<code>"abcd"</code>) are all ignorable, so the second string can be compared to the first string beginning with the space. Starting with the space in both the first string and the second string, then, the above <code>SequenceMatcher</code> finds ten matching characters (five in each string) and 4 non-matching characters (the ignorable first four characters in the second string). This gives you a ratio of 10/14 (0.7142857142857143).</p> <p>In your case, then, the first string <code>"a b c"</code> matches the second string at indices 0, 1, and 2 (with values <code>"a b"</code>). Index 3 of the first string (<code>" "</code>) does not have a match but is ignored with regard to the length of the match. Since the space is ignored, index 4 (<code>"c"</code>) matches index 3 of the second string. Thus 8 of your 9 characters match, giving you a ratio of <code>0.88888888888888</code>.</p> <p>You might want to try this instead:</p> <pre><code>&gt;&gt;&gt; c = a.replace(' ', '') &gt;&gt;&gt; d = b.replace(' ', '') &gt;&gt;&gt; difflib.SequenceMatcher(a=c, b=d).ratio() 1.0 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload