Index: Lib/difflib.py =================================================================== --- Lib/difflib.py (revision 64497) +++ Lib/difflib.py (working copy) @@ -203,11 +203,10 @@ # isbjunk # for x in b, isbjunk(x) == isjunk(x) but much faster; # it's really the has_key method of a hidden dict. - # DOES NOT WORK for x in a! # isbpopular # for x in b, isbpopular(x) is true iff b is reasonably long # (at least 200 elements) and x accounts for more than 1% of - # its elements. DOES NOT WORK for x in a! + # its elements. self.isjunk = isjunk self.a = self.b = None @@ -344,8 +343,8 @@ # lot of junk in the sequence, the number of *unique* junk # elements is probably small. So the memory burden of keeping # this dict alive is likely trivial compared to the size of b2j. - self.isbjunk = junkdict.has_key - self.isbpopular = populardict.has_key + self.isbjunk = junkdict.__contains__ + self.isbpopular = populardict.__contains__ def find_longest_match(self, alo, ahi, blo, bhi): """Find longest matching block in a[alo:ahi] and b[blo:bhi]. @@ -654,9 +653,7 @@ >>> s.real_quick_ratio() 1.0 """ - - matches = reduce(lambda sum, triple: sum + triple[-1], - self.get_matching_blocks(), 0) + matches = sum(triple[-1] for triple in self.get_matching_blocks()) return _calculate_ratio(matches, len(self.a) + len(self.b)) def quick_ratio(self): @@ -677,12 +674,9 @@ # avail[x] is the number of times x appears in 'b' less the # number of times we've seen it in 'a' so far ... kinda avail = {} - availhas, matches = avail.has_key, 0 + matches = 0 for elt in self.a: - if availhas(elt): - numb = avail[elt] - else: - numb = fullbcount.get(elt, 0) + numb = avail.get(elt, fullbcount.get(elt, 0)) avail[elt] = numb - 1 if numb > 0: matches = matches + 1