0

I have a task for a school test. We have to create a program in python 3. The program has to search in a file, like a dictionary with all kinds of words for the right matches. If the search word would be: B?X?? The rustles could be: BOXER BOXEN BOXTE .... But it is not just one word, in a separate file the search words are stored, now I have to open both files and print out the correct answers. For one word it works like this:

if len(word) == len(search):
    ok = True
    for index in range(len(word)):
        character = search[index]
        if character == "?":
            continue
        if character != word[index]:
            ok = False
            break
    if ok:
        print(word)

In addition to adding the other text i have to convert the german letter ä in to ae, ö in oe and ü in oe, as well as ß into ss. That is the part were I am stuck... I am new to this, but I have searched the board and couldn't find anything.

  • Stack Overflow will not do your homework for you. Have a look at the Python regex (regular expression) capabilities. Also, http://stackoverflow.com/questions/9452108/how-to-use-string-replace-in-python-3-x – lit May 16 '17 at 18:21
  • This looks like the answer you need. http://stackoverflow.com/questions/3194516/replace-special-characters-with-ascii-equivalent or http://stackoverflow.com/questions/1382998/latin-1-to-ascii – Mike - SMT May 16 '17 at 18:29
  • I don't want that someone does my homework, I just want to learn how to code the task. I just wanted to be honest for what I need it. –  May 16 '17 at 18:30

1 Answers1

0

Using Python's replace method on strings, you could loop through your known list of characters and swap them out.

Matt R. Wilson
  • 7,268
  • 5
  • 32
  • 48
  • This really is not an answer. This is better as a comment. If you are trying to answer the OP maybe you should provide an example. – Mike - SMT May 16 '17 at 18:21
  • I beg to differ. In the case of homework, I have no problem pointing the OP in the right direction with proper documentation, but I'm not going to write the code for them. – Matt R. Wilson May 25 '17 at 15:34
  • That is my point. You can link documentation in the comments section. If you are not willing to answer the question with a usable example then you should put your link to the documentation in the comments. You don't have to do the problem for them but provide a functioning example of the replace method to show its use. And as noted [here](https://stackoverflow.com/help/how-to-answer) you should also quote the relevant section of the linked site. – Mike - SMT May 25 '17 at 15:45