I'm trying to create a function that compares characters in the same position of two strings of same length and returns the count of their differences.
For instance,
a = "HORSE"
b = "TIGER"
And it would return 5 (as all characters in the same position are different)
Here's what I've been working on.
def Differences(one, two):
difference = []
for i in list(one):
if list(one)[i] != list(two)[i]:
difference = difference+1
return difference
That gives an error "List indices must be integers not strings"
And so I've tried turning it to int by using int(ord(
def Differences(one, two):
difference = 0
for i in list(one):
if int(ord(list(one)[i])) != int(ord(list(two)[i])):
difference = difference+1
return difference
Which also returns the same error.
When I print list(one)[1] != list(two)[1] it eithers returns True or False, as the comparison is correctly made.
Can you tell me how to correct my code for this purpose?