- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditDistanceProblem.py
More file actions
Latest commit
32 lines (27 loc) · 621 Bytes
/
Copy patheditDistanceProblem.py
File metadata and controls
32 lines (27 loc) · 621 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
importpprint,sys
defedit_distance(a,b):
num_row=len(a)+1
num_col=len(b)+1
a=' '+a
b=' '+b
#making rows to range from 0 to num_row
printa,b
tb={}
foriinrange(0,num_row):
tb[i,0]=i
forjinrange(0,num_col):
tb[0,j]=j
foriinrange(1,num_row):
forjinrange(1,num_col):
tb[i,j]=0
#table set now
#starting from 1
#pprint.pprint(tb)
forrowinrange(1,num_row):
forcolinrange(1,num_col):
ifa[col-1] ==b[row-1]:
tb[row,col]=tb[row-1,col-1]
else:
tb[row,col]=min(tb[row,col-1]+1,tb[row-1,col]+1,tb[row-1,col-1]+1)
printtb[len(a)-1,len(b)-1]
edit_distance('read','bed')