I have a method, that computes the number of differences in two strings, and outputs where the differences are.
def method(a):
count=0
s1="ABC"
for i in range (len(a)):
if not a[i]==s1[i]:
count=count+1
else:
count=count+0
return a,count,difference(a, s1)
On input ex CBB, this method outputs
('CBB', 2, [1, 0, 1])
What I really need is for this method to do the same, but where is not only compares to a single string in s1, but to a list of strings
s1 = ['ACB', 'ABC', 'ABB']
Anyone with a smart method to do this?
the
comparefunction calculates the number of differences (and map of differences that you had been creating withdifference()). I rewrote the compare function to take a base string to be compared to,src, so that you don’t get stuck with comparing to"ABC"all the time.The
compare_to_manyfunction simply goes through a list of strings to compare to,srcs, and creates a list of the comparisons between those base strings and a test stringtest.EDIT:
After clarification in the comments, @X-Pender needs the source list to be hardcoded. This can be reflected by the following, single function: