-1

Im trying to make it so for example, ķ==k , but im having trouble finding a way that dosent replace the "ķ" to "k". Essentially i want them to mean the same thing. Im making a hangman game and since its in Latvian, I have been given a task to make the letters that the user will guess/input mean the same as a letter without accent.

minejums = input("Ievadi minējamo burtu: ")

latviesuburti = {"ā": "a", "č": "c", "ē": "e", "ģ": "g", "ī": "i", "ķ": "k", "ļ": "l", "ņ": "n", "š": "s", "ū": "u", "ž": "z"}

My idea so far was to use a dictionary. I will use a for loop, but i dont know what function to use. Please help.

  • Does this answer your question? [What is the best way to remove accents (normalize) in a Python unicode string?](https://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-normalize-in-a-python-unicode-string) – luk2302 Jan 21 '23 at 17:29
  • Have you tried anything? What is the problem with what you tried? I suggest looking up the documentation (it just googling) for replacing characters in a string. – zvone Jan 21 '23 at 17:30

1 Answers1

0

Since you don't want to actually change the letters in the puzzle, I would define a function that uses the dict to map each letter onto the bare Latin equivalent, and just always compare letters by passing both of them through the function first.

latviesuburti = {"ā": "a", "č": "c", "ē": "e", "ģ": "g", "ī": "i", 
                 "ķ": "k", "ļ": "l", "ņ": "n", "š": "s", "ū": "u", 
                 "ž": "z"}

def canonicalize(letter):         
    return latviesuburti.get(letter, letter)

...
for letter in puzzle:
    if canonicalize(guess) == canonicalize(letter):
        ... handle a correct guess ...
Mark Reed
  • 91,912
  • 16
  • 138
  • 175