[Python-checkins] python/dist/src/Lib difflib.py,1.18,1.19
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sun Jun 13 05:57:36 EDT 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21873
Modified Files:
difflib.py
Log Message:
Apply heapq.nlargest() to find best matches.
Index: difflib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/difflib.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** difflib.py 12 Feb 2004 17:35:06 -0000 1.18
--- difflib.py 13 Jun 2004 09:57:33 -0000 1.19
***************
*** 30,33 ****
--- 30,35 ----
'unified_diff']
+ import heapq
+
def _calculate_ratio(matches, length):
if length:
***************
*** 704,710 ****
# Move the best scorers to head of list
! result.sort(reverse=True)
# Strip scores for the best n matches
! return [x for score, x in result[:n]]
def _count_leading(line, ch):
--- 706,712 ----
# Move the best scorers to head of list
! result = heapq.nlargest(result, n)
# Strip scores for the best n matches
! return [x for score, x in result]
def _count_leading(line, ch):
More information about the Python-checkins
mailing list