Skip to content

Commit 01bff2c

Browse files
committed
suggestion_list: improve readability
Replicates graphql/graphql-js@bd4deb0
1 parent 24ada2f commit 01bff2c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/graphql/pyutils/suggestion_list.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@ def measure(self, option: str):
6767
for j in range(1, b_len + 1):
6868
cost = 0 if a[i - 1] == b[j - 1] else 1
6969

70-
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
70+
current_cell = min(
71+
d[i - 1][j] + 1, # delete
72+
d[i][j - 1] + 1, # insert
73+
d[i - 1][j - 1] + cost, # substitute
74+
)
7175

7276
if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]:
73-
d[i][j] = min(d[i][j], d[i - 2][j - 2] + 1)
77+
# transposition
78+
current_cell = min(current_cell, d[i - 2][j - 2] + 1)
79+
80+
d[i][j] = current_cell
7481

7582
return d[a_len][b_len]

0 commit comments

Comments
 (0)