What is the best way to unpack SequenceMatcher
loop results in Python so that values can be easily accessed and processed?
from difflib import *
orig = "1234567890"
commented = "123435456353453578901343154"
diff = SequenceMatcher(None, orig, commented)
match_id = []
for block in diff.get_matching_blocks():
match_id.append(block)
print(match_id)
String integers represent Chinese Characters.
The current iteration code stores match results in a list like this:
match_id
[Match(a=0, b=0, size=4), Match(a=4, b=7, size=2), Match(a=6, b=16, size=4), Match(a=10, b=27, size=0)]
I'd eventually like to mark out the comments with "{{"
and "}}"
like so:
"1234{{354}}56{{3534535}}7890{{1343154}}"
Which means, I am interested in unpacking the above SequenceMatcher
results and do some calculations on specific b
and size
values to yield this sequence:
rslt = [[0+4,7],[7+2,16],[16+4,27]]
which is a repetition of [b[i]+size[i],b[i+1]]
.