String Translate in Python

Level 3105 keystrokes

This replaces characters using a translation table created with str.maketrans().

Python code

# Create a string to transform
1text = "hello world"
# maketrans creates mapping: a->1, e->2, i->3, o->4, u->5
2table = str.maketrans("aeiou", "12345")
# translate applies the character mapping
3result = text.translate(table)
# Print: h2ll4 w4rld (vowels replaced with numbers)
4print(result)

Output

h2ll4 w4rld
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • "× 6
  • (× 3
  • )× 3
  • =× 3
  • .× 2
  • ,× 1

More Python examples at level 3

← Python typing practice