@@ -16,24 +16,35 @@ def dist(i, j):
1616 if i > 0 :
1717 base = dist (i - 1 , j )
1818 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+ )
2325 if j > 0 :
2426 base = dist (i , j - 1 )
2527 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+ )
3034 if i > 0 and j > 0 :
3135 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+ )
3748 step = min (paths , key = lambda a : a ["cost" ])
3849 memory [(i , j )] = step
3950 return memory [(i , j )]
0 commit comments