Wednesday, February 21, 2024
HomeSoftware EngineeringThe way to use a Translation Desk to Exchange Characters in Python

The way to use a Translation Desk to Exchange Characters in Python


Python gives the flexibility to create Translation Tables.

our_text = "That is an instance of some textual content"
translation_table = str.maketrans("abefilostz", "4636110572")

print(our_text)
#That is an instance of some textual content

print(our_text.translate(translation_table))
# Th15 15 4n 3x4mp13 06 50m3 73x7

First we create a Translation Desk by calling str.maketrans(x, y, z), passing in our characters we need to translate from and to.

Then we apply our translate(desk) to a string utilizing our newly created Translation Desk.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments