heres my code
from operator import itemgetter
class Operation(Enum):
"""Operations"""
DELETED = 1
INSERTED = 2
SUBSTITUTED = 3
def __str__(self):
return str(self.name.lower())
def distances(a, b):
"""Calculate edit
distance from a to b"""
len_a = len(a)
len_b = len(b)
twod = [[ ("0","none") for j in range(len_b + 1)] for i in range(len_a + 1)]
for i in range(1,len_a + 1 ):
twod[i][0] = (i,"D")
for j in range(1,len_b + 1 ):
twod[0][j] = (j,"I")
for i in range(1,len_a + 1):
for j in range(1 , len_b + 1):
# what woud be cost if the twod[i][j] is taken from twod[i-1][j-1]
if (a[i] == b[j]):
c = twod[i-1][j-1][0]
else:
c = twod[i-1][j-1][0] + 1
# writing a temporary list which could directly give the operation based on the position of min cost
arr_list = [(twod[i-1][j][0]+1,'D'),(twod[i][j-1][0]+1,'I'),(c,'S')]
# getting the (cost,operation) into twod[i][j] based on min cost
twod[i][j] = min(arr_list, key=lambda x:x[0])
return twod
here is the error
~/similarities/ $ ./score LesMis1.txt LesMis2.txt
Traceback (most recent call last):
File "./score", line 35, in <module>
main()
File "./score", line 30, in main
d = distances(file1, file2)
File "/home/ubuntu/similarities/helpers.py", line 43, in distances
twod[i][j] = min(arr_list, key=lambda x:x[0])
TypeError: '<' not supported between instances of 'str' and 'int'