@@ -18,10 +18,18 @@ def compute_transform_tables(
18
18
insert_cost : int ,
19
19
) -> tuple [list [list [int ]], list [list [str ]]]:
20
20
"""
21
- Finds the most cost efficient sequence for converting one string into another.
22
-
23
- >>> compute_transform_tables("cat", "cut", 1, 2, 3, 3)
24
- ([[0, 3, 6, 9], [3, 1, 4, 7], [6, 4, 3, 6], [9, 7, 6, 4]], [['0', 'Ic', 'Iu', 'It'], ['Dc', 'Cc', 'Iu', 'It'], ['Da', 'Da', 'Rau', 'Rat'], ['Dt', 'Dt', 'Rtu', 'Ct']])
21
+ Finds the most cost efficient sequence
22
+ for converting one string into another.
23
+
24
+ >>> costs, operations = compute_transform_tables("cat", "cut", 1, 2, 3, 3)
25
+ >>> costs[0][:4]
26
+ [0, 3, 6, 9]
27
+ >>> costs[2][:4]
28
+ [6, 4, 3, 6]
29
+ >>> operations[0][:4]
30
+ ['0', 'Ic', 'Iu', 'It']
31
+ >>> operations[3][:4]
32
+ ['Dt', 'Dt', 'Rtu', 'Ct']
25
33
26
34
>>> compute_transform_tables("", "", 1, 2, 3, 3)
27
35
([[0]], [['0']])
@@ -38,7 +46,9 @@ def compute_transform_tables(
38
46
["0" for _ in range (len_destination_seq + 1 )] for _ in range (len_source_seq + 1 )
39
47
]
40
48
41
- # Removed ':c' specifier as it is generally used for integers to convert to a Unicode character not strings.
49
+ # Removed ':c' specifier as it is generally
50
+ # used for integers to convert to a Unicode
51
+ # character not strings.
42
52
for i in range (1 , len_source_seq + 1 ):
43
53
costs [i ][0 ] = i * delete_cost
44
54
ops [i ][0 ] = f"D{ source_seq [i - 1 ]} "
@@ -69,9 +79,12 @@ def compute_transform_tables(
69
79
70
80
def assemble_transformation (ops : list [list [str ]], i : int , j : int ) -> list [str ]:
71
81
"""
72
- Assembles the transformations based on the information in the ops table.
73
-
74
- >>> ops = [['0', 'Ic', 'Iu', 'It'], ['Dc', 'Cc', 'Iu', 'It'], ['Da', 'Da', 'Rau', 'Rat'], ['Dt', 'Dt', 'Rtu', 'Ct']]
82
+ Assembles the transformations based on the ops table.
83
+
84
+ >>> ops = [['0', 'Ic', 'Iu', 'It'],
85
+ ... ['Dc', 'Cc', 'Iu', 'It'],
86
+ ... ['Da', 'Da', 'Rau', 'Rat'],
87
+ ... ['Dt', 'Dt', 'Rtu', 'Ct']]
75
88
>>> x = len(ops) - 1
76
89
>>> y = len(ops[0]) - 1
77
90
>>> assemble_transformation(ops, x, y)
@@ -150,4 +163,4 @@ def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]:
150
163
print ("" .join (string ))
151
164
print ("Cost: " , cost )
152
165
153
- file .write ("\r \n Minimum cost: " + str (cost ))
166
+ file .write ("\r \n Minimum cost: " + str (cost ))
0 commit comments