@@ -16,24 +16,35 @@ def dist(i, j):
16
16
if i > 0 :
17
17
base = dist (i - 1 , j )
18
18
op = {"op" : "remove" , "idx" : i - 1 }
19
- paths .append ({
20
- "ops" : base ["ops" ] + [op ],
21
- "cost" : base ["cost" ] + 1 ,
22
- })
19
+ paths .append (
20
+ {
21
+ "ops" : base ["ops" ] + [op ],
22
+ "cost" : base ["cost" ] + 1 ,
23
+ }
24
+ )
23
25
if j > 0 :
24
26
base = dist (i , j - 1 )
25
27
op = {"op" : "add" , "idx" : j - 1 , "value" : output [j - 1 ]}
26
- paths .append ({
27
- "ops" : base ["ops" ] + [op ],
28
- "cost" : base ["cost" ] + 1 ,
29
- })
28
+ paths .append (
29
+ {
30
+ "ops" : base ["ops" ] + [op ],
31
+ "cost" : base ["cost" ] + 1 ,
32
+ }
33
+ )
30
34
if i > 0 and j > 0 :
31
35
base = dist (i - 1 , j - 1 )
32
- op = {"op" : "replace" , "idx" : i - 1 , "original" : input [i - 1 ], "value" : output [j - 1 ]}
33
- paths .append ({
34
- "ops" : base ["ops" ] + [op ],
35
- "cost" : base ["cost" ] + 1 ,
36
- })
36
+ op = {
37
+ "op" : "replace" ,
38
+ "idx" : i - 1 ,
39
+ "original" : input [i - 1 ],
40
+ "value" : output [j - 1 ],
41
+ }
42
+ paths .append (
43
+ {
44
+ "ops" : base ["ops" ] + [op ],
45
+ "cost" : base ["cost" ] + 1 ,
46
+ }
47
+ )
37
48
step = min (paths , key = lambda a : a ["cost" ])
38
49
memory [(i , j )] = step
39
50
return memory [(i , j )]
0 commit comments