21 lines
546 B
Python
21 lines
546 B
Python
"""
|
|
Translate a string of text: letter a becomes z, b becomes y, ..., z becomes a.
|
|
"""
|
|
|
|
class Translate:
|
|
def translation(self, text: str) -> str:
|
|
# Create translation table for a-z
|
|
import string
|
|
table = str.maketrans(
|
|
string.ascii_lowercase,
|
|
string.ascii_lowercase[::-1]
|
|
)
|
|
return text.translate(table)
|
|
|
|
# Example usage
|
|
if __name__ == "__main__":
|
|
t = Translate()
|
|
sentence = "Tobeornottobethatisthequestion"
|
|
print(t.translation("sentence")) # Output: zyxcba
|
|
|
|
|