Python Forum
How do you switch all alphabet into different characters?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you switch all alphabet into different characters?
#1
I want to switch multiple characters into other characters e.g
m--->n
lo--->om

no never-->mo mever
hello-->helom

i.e .replace() but for multiple characters and character groups like dipthongs
Reply
#2
You can store your replacements in a dictionary and then you can do the replacement with simple loop:

replacements = {
    "m": "n",
    "lo": "om",
    "no never": "mo mever",
    "hello": "helom"
}

my_string = "m lo"

for (old, new) in replacements.items():
    my_string = my_string.replace(old, new)

print(my_string)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to fix bugs in Morse alphabet code? dokipo 10 2,870 Oct-26-2021, 06:43 PM
Last Post: deanhystad
  best way to use switch case? korenron 8 3,029 Aug-18-2021, 03:16 PM
Last Post: naughtyCat
  How do I do this? Switch Case? mstichler 4 2,595 Jun-05-2020, 10:27 AM
Last Post: snippsat
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,794 May-15-2020, 01:37 PM
Last Post: snippsat
  switch limitations MuntyScruntfundle 3 2,389 Jan-27-2019, 06:11 PM
Last Post: aakashjha001

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020