mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-02 20:06:50 +00:00
Update a1z26.py to use ALPHABET_OFFSET constant
This commit is contained in:
parent
03a42510b0
commit
9e5f38783f
@ -8,13 +8,14 @@ http://bestcodes.weebly.com/a1z26.html
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
ALPHABET_OFFSET = 96
|
||||||
|
|
||||||
def encode(plain: str) -> list[int]:
|
def encode(plain: str) -> list[int]:
|
||||||
"""
|
"""
|
||||||
>>> encode("myname")
|
>>> encode("myname")
|
||||||
[13, 25, 14, 1, 13, 5]
|
[13, 25, 14, 1, 13, 5]
|
||||||
"""
|
"""
|
||||||
return [ord(elem) - 96 for elem in plain]
|
return [ord(elem) - ALPHABET_OFFSET for elem in plain]
|
||||||
|
|
||||||
|
|
||||||
def decode(encoded: list[int]) -> str:
|
def decode(encoded: list[int]) -> str:
|
||||||
@ -22,7 +23,7 @@ def decode(encoded: list[int]) -> str:
|
|||||||
>>> decode([13, 25, 14, 1, 13, 5])
|
>>> decode([13, 25, 14, 1, 13, 5])
|
||||||
'myname'
|
'myname'
|
||||||
"""
|
"""
|
||||||
return "".join(chr(elem + 96) for elem in encoded)
|
return "".join(chr(elem + ALPHABET_OFFSET) for elem in encoded)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user