There was an error while loading. Please reload this page.
1 parent f3b68b3 commit 74a7c67Copy full SHA for 74a7c67
2 files changed
Doc/library/difflib.rst
@@ -358,6 +358,16 @@ The :class:`SequenceMatcher` class has this constructor:
358
.. versionadded:: 3.2
359
The *autojunk* parameter.
360
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
371
:class:`SequenceMatcher` objects have the following methods:
372
373
@@ -538,7 +548,7 @@ different results due to differing levels of approximation, although
538
548
SequenceMatcher Examples
539
549
------------------------
540
550
541
-This example compares two strings, considering blanks to be "junk:"
551
+This example compares two strings, considering blanks to be "junk":
542
552
543
553
>>> s = SequenceMatcher(lambda x: x == " ",
544
554
... "private Thread currentThread;",
Lib/difflib.py
@@ -213,6 +213,10 @@ def __init__(self, isjunk=None, a='', b='', autojunk=True):
213
# (at least 200 elements) and x accounts for more than 1 + 1% of
214
# its elements (when autojunk is enabled).
215
# 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).
220
221
self.isjunk = isjunk
222
self.a = self.b = None
@@ -321,7 +325,7 @@ def __chain_b(self):
321
325
indices.append(i)
322
326
323
327
# Purge junk elements
324
- junk = set()
328
+ self.bjunk = junk = set()
329
isjunk = self.isjunk
330
if isjunk:
331
for elt in list(b2j.keys()): # using list() since b2j is modified
@@ -330,7 +334,7 @@ def __chain_b(self):
334
del b2j[elt]
335
332
336
# Purge popular elements that are not junk
333
- popular = set()
337
+ self.bpopular = popular = set()
338
n = len(b)
339
if self.autojunk and n >= 200:
340
ntest = n // 100 + 1
0 commit comments