I am new to Python and also this problem (https://www.spoj.com/problems/EDIST/) is my first problem in spoj in Python. I am not sure why I am getting runtime error. Is this a format problem? I submitted with Python (cpython 2.7.16)
def edit_distance(s, t):
sz_s = len(s)
sz_t = len(t)
dp = [[0] * (sz_t + 2) for i in range(sz_s + 2)]
for i in range(1, sz_s + 1):
dp[i][0] = i
for j in range(1, sz_t + 1):
dp[0][j] = j
for i in range(1, sz_s + 1):
for j in range(1, sz_t + 1):
dp[i][j] = min(
dp[i - 1][j] + 1,
dp[i][j - 1] + 1,
dp[i - 1][j - 1] + (1 if s[i - 1] != t[j - 1] else 0)
)
return dp[sz_s][sz_t]
def main():
T = int(input())
for i in range(T):
str1 = input()
str2 = input()
print(int(edit_distance(str1, str2)))
main()