Skip to content

Commit 97c01c2

Browse files
committed
minor simplification and change in var name
1 parent 4f308e2 commit 97c01c2

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Python/chapter01/1.5 - OneAway/miguel_1.5_sol.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,16 @@ def one_away(s1: str, s2: str) -> bool:
4343
s_short = s1 if len(s1) < len(s2) else s2
4444
s_long = s1 if len(s1) > len(s2) else s2
4545

46-
addend = 0
46+
added = 0
4747
for i, c in enumerate(s_short):
48-
if c == s_long[i + addend]:
48+
if c == s_long[i + added]:
4949
continue
50-
if i == i + addend:
51-
# addend is 0, will check next char in next iteration
52-
addend += 1
53-
continue
54-
# otherwise, addend is not 0, and we did not match characters.
55-
# guaranteed at least 2 edit distance
56-
return False
50+
# chars didn't match, will check next char in next iteration
51+
added += 1
52+
if added > 1:
53+
# added more than once, and we did not match characters.
54+
# guaranteed at least 2 edit distance
55+
return False
5756
return True
5857

5958

0 commit comments

Comments
 (0)