'I dont understand the output of diff function from difflib module
Im having a hard time understanding the output of the Difflib module of python. This output seems fine here:
import difflib
from difflib import SequenceMatcher, Differ
diff = Differ()
test_string_1 = "Ava D Ava: I'll try... :)"
test_string_2 = "AvaDAva:I'lltry...:)"
diffs = list(diff.compare(test_string, test_string_2))
print(diffs)
[
" A",
" v",
" a",
"- ",
"- :",
" D",
"- ",
" A",
" v",
" a",
" :",
"- ",
" I",
" '",
" l",
" l",
"- ",
" t",
" r",
" y",
" .",
" .",
" .",
"- ",
" :",
" )",
]
But when add a colon before the D character the output changes drastically:
test_string_1 = "Ava :D Ava: I'll try... :)"
test_string_2 = "Ava:DAva:I'lltry...:)"
diffs = list(diff.compare(test_string, test_string_2))
['- A',
'- v',
'- a',
'- ',
'- :',
'- D',
'- ',
' A',
' v',
' a',
' :',
'- ',
'+ D',
'+ A',
'+ v',
'+ a',
'+ :',
' I',
" '",
' l',
' l',
'- ',
' t',
' r',
' y',
' .',
' .',
' .',
'- ',
' :',
' )']
The output suggests both strings start differently when they are the same. I really need help, this doesn't make sense to me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
