Python Forum
Why this simple function doesnt work?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why this simple function doesnt work?
#9
If it is one-char to one-char translation, you can do even more elegant
def correct(text):
    corrections = str.maketrans('15', 'IS') # or corrections = str.maketrans({'1':'I', '5':'S'})
    return text.translate(corrections)

print(correct("1teruje5z t0"))
this will not work for one-char to many-char-string translation
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Why this simple function doesnt work? - by buran - Jan-05-2019, 12:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 232 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Pydoc documentation doesnt work Cosmosso 5 4,263 Nov-25-2023, 11:17 PM
Last Post: vidito
  pip install requests doesnt work misodca 8 5,558 Jul-07-2023, 08:04 AM
Last Post: zyple
  Ldap3 Python print(conn.entries) doesnt work ilknurg 15 5,565 Dec-28-2022, 11:22 AM
Last Post: shad
  I dont know why my function won't work? MehHz2526 3 1,149 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  pip install pystyle doesnt work person_probably 2 2,002 Sep-23-2022, 02:59 PM
Last Post: person_probably
  Why doesnt chunk generation work? LotosProgramer 1 1,908 Apr-02-2022, 08:25 AM
Last Post: deanhystad
  Join dataframes... So simple but I can't work it out! snakes 1 1,341 Oct-27-2021, 09:15 AM
Last Post: snakes
  time function does not work tester_V 4 2,945 Oct-17-2021, 05:48 PM
Last Post: tester_V
  write new function or change the old one to work "smartter? korenron 3 1,924 Aug-09-2021, 10:36 AM
Last Post: jamesaarr

Forum Jump:

User Panel Messages

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