0

I have been trying to make something like an encoder:

here is my idea

dict = {
    1: "!",
    2: "@"
}

in = 21 # Input number in

out = ?

print(out) # Returns "@!"

Is there any way I could perform this?

1 Answer 1

1

What you want is exactly the translate function of str:

x="12"
y="!@"
in=12
txt=str(in)
mapping = txt.maketrans(x, y)
out=txt.translate(mapping)

You can check the complete reference here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.