This is the behaviour I want:
a: IGADKYFHARGNYDAA
c: KGADKYFHARGNYEAA
2 difference(s).
With difflib.ndiff you can do this in a one-liner that's still somewhat comprehensible:
>>> import difflib
>>> a = 'IGADKYFHARGNYDAA'
>>> c = 'KGADKYFHARGNYEAA'
>>> sum([i[0] != ' ' for i in difflib.ndiff(a, c)]) / 2
2
(sum
works here because, well, kind of True == 1
and False == 0
)
The following makes it clear what's happening and why the / 2
is needed:
>>> [i for i in difflib.ndiff(a,c)]
['- I',
'+ K',
' G',
' A',
' D',
' K',
' Y',
' F',
' H',
' A',
' R',
' G',
' N',
' Y',
'- D',
'+ E',
' A',
' A']
This also works well if the strings have a different length.