Skip to content

Commit 53181d1

Browse files
committed
Use list accumulation in rot13.py
1 parent 6c04620 commit 53181d1

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

ciphers/rot13.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ def dencrypt(s: str, n: int = 13) -> str:
99
>>> dencrypt(s) == msg
1010
True
1111
"""
12-
out = ""
12+
out = []
13+
1314
for c in s:
1415
if "A" <= c <= "Z":
15-
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
16+
out.append(chr(ord("A") + (ord(c) - ord("A") + n) % 26))
1617
elif "a" <= c <= "z":
17-
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
18+
out.append(chr(ord("a") + (ord(c) - ord("a") + n) % 26))
1819
else:
19-
out += c
20-
return out
20+
out.append(c)
21+
22+
return "".join(out)
2123

2224

2325
def main() -> None:

0 commit comments

Comments
 (0)