fork download
  1. word1 = input()
  2. word2 = input()
  3.  
  4. m = len(word1)
  5. n = len(word2)
  6. table = [[0] * (n + 1) for _ in range(m + 1)]
  7.  
  8. for i in range(m + 1):
  9. table[i][0] = i
  10.  
  11. for j in range(n + 1):
  12. table[0][j] = j
  13.  
  14. for i in range(1, m + 1):
  15. for j in range(1, n + 1):
  16. if word1[i - 1] == word2[j - 1]:
  17. table[i][j] = table[i - 1][j - 1]
  18. # if same move on
  19. else:
  20. table[i][j] = 1 + min(table[i - 1][j], table[i]
  21. [j - 1], table[i - 1][j - 1])
  22. # else check min of removing one from word1, one from word2, or both
  23. print(table[-1][-1])
Success #stdin #stdout 0.04s 9560KB
stdin
ioana
dana
stdout
2