Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74a7c67

Browse files
committed
1 parent f3b68b3 commit 74a7c67

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Doc/library/difflib.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ The :class:`SequenceMatcher` class has this constructor:
358358
.. versionadded:: 3.2
359359
The *autojunk* parameter.
360360

361+
SequenceMatcher objects get three data attributes: *bjunk* is the
362+
set of elements of b for which *isjunk* is True; *bpopular* is the set of non-
363+
junk elements considered popular by the heuristic (if it is not disabled);
364+
*b2j* is a dict mapping the remaining elements of b to a list of positions where
365+
they occur. All three are reset whenever *b* is reset with :meth:`set_seqs`
366+
or :meth:`set_seq2`.
367+
368+
.. versionadded:: 3.2
369+
The *bjunk* and *bpopular* attributes.
370+
361371
:class:`SequenceMatcher` objects have the following methods:
362372

363373

@@ -538,7 +548,7 @@ different results due to differing levels of approximation, although
538548
SequenceMatcher Examples
539549
------------------------
540550

541-
This example compares two strings, considering blanks to be "junk:"
551+
This example compares two strings, considering blanks to be "junk":
542552

543553
>>> s = SequenceMatcher(lambda x: x == " ",
544554
... "private Thread currentThread;",

Lib/difflib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ def __init__(self, isjunk=None, a='', b='', autojunk=True):
213213
# (at least 200 elements) and x accounts for more than 1 + 1% of
214214
# its elements (when autojunk is enabled).
215215
# DOES NOT WORK for x in a!
216+
# bjunk
217+
# the items in b for which isjunk is True.
218+
# bpopular
219+
# nonjunk items in b treated as junk by the heuristic (if used).
216220

217221
self.isjunk = isjunk
218222
self.a = self.b = None
@@ -321,7 +325,7 @@ def __chain_b(self):
321325
indices.append(i)
322326

323327
# Purge junk elements
324-
junk = set()
328+
self.bjunk = junk = set()
325329
isjunk = self.isjunk
326330
if isjunk:
327331
for elt in list(b2j.keys()): # using list() since b2j is modified
@@ -330,7 +334,7 @@ def __chain_b(self):
330334
del b2j[elt]
331335

332336
# Purge popular elements that are not junk
333-
popular = set()
337+
self.bpopular = popular = set()
334338
n = len(b)
335339
if self.autojunk and n >= 200:
336340
ntest = n // 100 + 1

0 commit comments

Comments
 (0)