[Solved] library for string comparison in python [closed]


Not a library but an easy way to do what you want:

string_a="ABCD"
string_b = 'ADCT'

print ([ind for ind,char in enumerate(string_a) if string_b[ind] != char])
[1, 3]

enumerate gives you the index of each char through the string, if string_b[ind] != char checks if the chars at corresponding indexes are not the same.

string_b will have to be the same length or shorter than string_a or you will get an index error.

zip will work for uneven length strings:

[ ind for ind, tup  in enumerate (zip(string_a,string_b)) if tup[0] != tup[1]]

solved library for string comparison in python [closed]