<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 8, 2015, at 08:15, Tal Einat <<a href="mailto:taleinat@gmail.com" class="">taleinat@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">On Mon, Jun 8, 2015 at 11:44 AM, Serhiy Storchaka <<a href="mailto:storchaka@gmail.com" class="">storchaka@gmail.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">If such function will be added, I think it needs better name. E.g.<br class="">difflib.isclose(a, b, threshold).<br class=""></blockquote><br class="">Indeed, this is somewhat similar in concept to the recently-added<br class="">math.isclose() function, and could use a similar signature, i.e.:<br class="">difflib.SequenceMatcher.isclose(a, b, rel_tol=None, abs_tol=None).<br class=""><br class="">However, the real issue here is whether this is important enough to be<br class="">included in the stdlib.<br class=""></div></blockquote></div><div class=""><br class=""></div><div class="">One thing I found is that the fact that stdlib try to be smart (human friendly diff) make it horribly slow[1]. </div><div class=""><br class=""></div><div class=""><div class="">>  SequenceMatcher tries to compute a "human-friendly diff" between two sequences.</div></div><div class=""><br class=""></div><div class="">If you are only interested in a quick ratio, especially on long sequences, I would suggest using another algorithm</div><div class="">which is not worse case scenario in n^3.</div><div class=""><br class=""></div><div class="">On some sequences computing the diff was several order of magnitude faster for me[2] (pure python).</div><div class="">At the point where quick-ratio was not needed.</div><div class=""><br class=""></div><div class="">Note also that SequeceMatcher(None, a, b) might not give the same result/ratio that SequenceMatcher(None, b, a)</div><div class=""><br class=""></div><div class=""><div class="">>>> SequenceMatcher(None,'aba', 'bca').get_matching_blocks()</div><div class=""> [Match(a=0, b=2, size=1), Match(a=3, b=3, size=0)]   # 1 common char</div><div class=""><br class=""></div><div class="">>>> SequenceMatcher(None,'bca','aba').get_matching_blocks()</div><div class=""> [Match(a=0, b=1, size=1), Match(a=2, b=2, size=1), Match(a=3, b=3, size=0)] # 2 common chars.</div></div><div class=""><br class=""></div><div class="">— </div><div class="">M</div><div class=""><br class=""></div><div class="">[1] For my application, I don’t really care about having Human Friendly diff, but the actual minimal diff. </div><div class="">     I do understand the need for this algorithm though. </div><div class="">[2] Well chosen Benchmark : <a href="http://i.imgur.com/cZPwR0H.png" class="">http://i.imgur.com/cZPwR0H.png</a></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>