1

I have a string

str = "abcdef"

and a mapping

map = {'a':'b','b':'c', 'c':'d'}

The expected output is

out_str = 'bcddef'

How can I apply mapping in one iteration in python?

0

1 Answer 1

1

Try:

s = "abcdef"
m = {"a": "b", "b": "c", "c": "d"}

print("".join(m.get(ch, ch) for ch in s))

Prints:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.