source
stringclasses 1
value | version
stringclasses 1
value | module
stringclasses 43
values | function
stringclasses 307
values | input
stringlengths 3
496
| expected
stringlengths 0
40.5k
| signature
stringclasses 0
values |
|---|---|---|---|---|---|---|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seqs
|
>>> s = SequenceMatcher()
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seqs
|
>>> s.set_seqs("abcd", "bcde")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seqs
|
>>> s.ratio()
|
0.75
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq1
|
>>> s = SequenceMatcher(None, "abcd", "bcde")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq1
|
>>> s.ratio()
|
0.75
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq1
|
>>> s.set_seq1("bcde")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq1
|
>>> s.ratio()
|
1.0
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq1
|
>>>
|
SequenceMatcher computes and caches detailed information about the
second sequence, so if you want to compare one sequence S against
many sequences, use .set_seq2(S) once and call .set_seq1(x)
repeatedly for each of the other sequences.
See also set_seqs() and set_seq2().
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq2
|
>>> s = SequenceMatcher(None, "abcd", "bcde")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq2
|
>>> s.ratio()
|
0.75
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq2
|
>>> s.set_seq2("abcd")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq2
|
>>> s.ratio()
|
1.0
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.set_seq2
|
>>>
|
SequenceMatcher computes and caches detailed information about the
second sequence, so if you want to compare one sequence S against
many sequences, use .set_seq2(S) once and call .set_seq1(x)
repeatedly for each of the other sequences.
See also set_seqs() and set_seq1().
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.find_longest_match
|
>>> s = SequenceMatcher(None, " abcd", "abcd abcd")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.find_longest_match
|
>>> s.find_longest_match(0, 5, 0, 9)
|
Match(a=0, b=4, size=5)
If isjunk is defined, first the longest matching block is
determined as above, but with the additional restriction that no
junk element appears in the block. Then that block is extended as
far as possible by matching (only) junk elements on both sides. So
the resulting block never matches on junk except as identical junk
happens to be adjacent to an "interesting" match.
Here's the same example as before, but considering blanks to be
junk. That prevents " abcd" from matching the " abcd" at the tail
end of the second sequence directly. Instead only the "abcd" can
match, and matches the leftmost "abcd" in the second sequence:
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.find_longest_match
|
>>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.find_longest_match
|
>>> s.find_longest_match(0, 5, 0, 9)
|
Match(a=1, b=0, size=4)
If no blocks match, return (alo, blo, 0).
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.find_longest_match
|
>>> s = SequenceMatcher(None, "ab", "c")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.find_longest_match
|
>>> s.find_longest_match(0, 2, 0, 1)
|
Match(a=0, b=0, size=0)
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_matching_blocks
|
>>> s = SequenceMatcher(None, "abxcd", "abcd")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_matching_blocks
|
>>> list(s.get_matching_blocks())
|
[Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_opcodes
|
>>> a = "qabxcd"
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_opcodes
|
>>> b = "abycdf"
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_opcodes
|
>>> s = SequenceMatcher(None, a, b)
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_opcodes
|
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
|
delete a[0:1] (q) b[0:0] ()
equal a[1:3] (ab) b[0:2] (ab)
replace a[3:4] (x) b[2:3] (y)
equal a[4:6] (cd) b[3:5] (cd)
insert a[6:6] () b[5:6] (f)
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> from pprint import pprint
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> a = list(map(str, range(1,40)))
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> b = a[:]
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> b[8:8] = ['i'] # Make an insertion
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> b[20] += 'x' # Make a replacement
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> b[23:28] = [] # Make a deletion
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> b[30] += 'y' # Make another replacement
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_grouped_opcodes
|
>>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
|
[[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
[('equal', 16, 19, 17, 20),
('replace', 19, 20, 20, 21),
('equal', 20, 22, 21, 23),
('delete', 22, 27, 23, 23),
('equal', 27, 30, 23, 26)],
[('equal', 31, 34, 27, 30),
('replace', 34, 35, 30, 31),
('equal', 35, 38, 31, 34)]]
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.ratio
|
>>> s = SequenceMatcher(None, "abcd", "bcde")
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.ratio
|
>>> s.ratio()
|
0.75
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.ratio
|
>>> s.quick_ratio()
|
0.75
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.ratio
|
>>> s.real_quick_ratio()
|
1.0
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_close_matches
|
>>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
|
['apple', 'ape']
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_close_matches
|
>>> import keyword as _keyword
| null |
|
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_close_matches
|
>>> get_close_matches("wheel", _keyword.kwlist)
|
['while']
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_close_matches
|
>>> get_close_matches("Apple", _keyword.kwlist)
|
[]
| null |
cpython
|
cfcd524
|
difflib
|
SequenceMatcher.get_close_matches
|
>>> get_close_matches("accept", _keyword.kwlist)
|
['except']
| null |
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> text1 = ''' 1. Beautiful is better than ugly.
... 2. Explicit is better than implicit.
... 3. Simple is better than complex.
... 4. Complex is better than complicated.
... '''.splitlines(keepends=True)
| null |
|
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> len(text1)
|
4
| null |
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> text1[0][-1]
|
'\n'
| null |
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> text2 = ''' 1. Beautiful is better than ugly.
... 3. Simple is better than complex.
... 4. Complicated is better than complex.
... 5. Flat is better than nested.
... '''.splitlines(keepends=True)
|
Next we instantiate a Differ object:
| null |
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> d = Differ()
|
Note that when instantiating a Differ object we may pass functions to
filter out line and character 'junk'. See Differ.__init__ for details.
Finally, we compare the two:
| null |
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> result = list(d.compare(text1, text2))
|
'result' is a list of strings, so let's pretty-print it:
| null |
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> from pprint import pprint as _pprint
| null |
|
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> _pprint(result)
|
[' 1. Beautiful is better than ugly.\n',
'- 2. Explicit is better than implicit.\n',
'- 3. Simple is better than complex.\n',
'+ 3. Simple is better than complex.\n',
'? ++\n',
'- 4. Complex is better than complicated.\n',
'? ^ ---- ^\n',
'+ 4. Complicated is better than complex.\n',
'? ++++ ^ ^\n',
'+ 5. Flat is better than nested.\n']
As a single multi-line string it looks like this:
| null |
cpython
|
cfcd524
|
difflib
|
Differ
|
>>> print(''.join(result), end="")
|
1. Beautiful is better than ugly.
- 2. Explicit is better than implicit.
- 3. Simple is better than complex.
+ 3. Simple is better than complex.
? ++
- 4. Complex is better than complicated.
? ^ ---- ^
+ 4. Complicated is better than complex.
? ++++ ^ ^
+ 5. Flat is better than nested.
| null |
cpython
|
cfcd524
|
difflib
|
Differ.compare
|
>>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
... 'ore\ntree\nemu\n'.splitlines(True))),
... end="")
|
- one
? ^
+ ore
? ^
- two
- three
? -
+ tree
+ emu
| null |
cpython
|
cfcd524
|
difflib
|
Differ._fancy_replace
|
>>> d = Differ()
| null |
|
cpython
|
cfcd524
|
difflib
|
Differ._fancy_replace
|
>>> results = d._fancy_replace(['abcDefghiJkl\n'], 0, 1,
... ['abcdefGhijkl\n'], 0, 1)
| null |
|
cpython
|
cfcd524
|
difflib
|
Differ._fancy_replace
|
>>> print(''.join(results), end="")
|
- abcDefghiJkl
? ^ ^ ^
+ abcdefGhijkl
? ^ ^ ^
| null |
cpython
|
cfcd524
|
difflib
|
Differ._qformat
|
>>> d = Differ()
| null |
|
cpython
|
cfcd524
|
difflib
|
Differ._qformat
|
>>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
... ' ^ ^ ^ ', ' ^ ^ ^ ')
| null |
|
cpython
|
cfcd524
|
difflib
|
Differ._qformat
|
>>> for line in results: print(repr(line))
...
|
'- \tabcDefghiJkl\n'
'? \t ^ ^ ^\n'
'+ \tabcdefGhijkl\n'
'? \t ^ ^ ^\n'
| null |
cpython
|
cfcd524
|
difflib
|
Differ.IS_LINE_JUNK
|
>>> IS_LINE_JUNK('\n')
|
True
| null |
cpython
|
cfcd524
|
difflib
|
Differ.IS_LINE_JUNK
|
>>> IS_LINE_JUNK(' # \n')
|
True
| null |
cpython
|
cfcd524
|
difflib
|
Differ.IS_LINE_JUNK
|
>>> IS_LINE_JUNK('hello\n')
|
False
| null |
cpython
|
cfcd524
|
difflib
|
Differ.IS_CHARACTER_JUNK
|
>>> IS_CHARACTER_JUNK(' ')
|
True
| null |
cpython
|
cfcd524
|
difflib
|
Differ.IS_CHARACTER_JUNK
|
>>> IS_CHARACTER_JUNK('\t')
|
True
| null |
cpython
|
cfcd524
|
difflib
|
Differ.IS_CHARACTER_JUNK
|
>>> IS_CHARACTER_JUNK('\n')
|
False
| null |
cpython
|
cfcd524
|
difflib
|
Differ.IS_CHARACTER_JUNK
|
>>> IS_CHARACTER_JUNK('x')
|
False
| null |
cpython
|
cfcd524
|
difflib
|
Differ.unified_diff
|
>>> for line in unified_diff('one two three four'.split(),
... 'zero one tree four'.split(), 'Original', 'Current',
... '2005-01-26 23:30:50', '2010-04-02 10:20:52',
... lineterm=''):
... print(line) # doctest: +NORMALIZE_WHITESPACE
|
--- Original 2005-01-26 23:30:50
+++ Current 2010-04-02 10:20:52
@@ -1,4 +1,4 @@
+zero
one
-two
-three
+tree
four
| null |
cpython
|
cfcd524
|
difflib
|
Differ.context_diff
|
>>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True),
... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')),
... end="")
|
*** Original
--- Current
***************
*** 1,4 ****
one
! two
! three
four
--- 1,4 ----
+ zero
one
! tree
four
| null |
cpython
|
cfcd524
|
difflib
|
Differ.ndiff
|
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
| null |
|
cpython
|
cfcd524
|
difflib
|
Differ.ndiff
|
>>> print(''.join(diff), end="")
|
- one
? ^
+ ore
? ^
- two
- three
? -
+ tree
+ emu
| null |
cpython
|
cfcd524
|
difflib
|
HtmlDiff.restore
|
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
| null |
|
cpython
|
cfcd524
|
difflib
|
HtmlDiff.restore
|
>>> diff = list(diff)
| null |
|
cpython
|
cfcd524
|
difflib
|
HtmlDiff.restore
|
>>> print(''.join(restore(diff, 1)), end="")
|
one
two
three
| null |
cpython
|
cfcd524
|
difflib
|
HtmlDiff.restore
|
>>> print(''.join(restore(diff, 2)), end="")
|
ore
tree
emu
| null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.