0

I currently have this second part of this function to convert words in a string using a dictionary. What is the best way of doing this with a list rather than a dictionary?

def multipleReplace(text,function):

    if function == 1:

    if function == 2:
        rc = re.compile(r"[A-Za-z_]\w*")
        def translate(match):
            word = match.group(0)
            return wordDict.get(word, word)
        return rc.sub(translate, text)

Thanks.

derkyzer
  • 161
  • 1
  • 1
  • 9
  • Can you explain more in detail (maybe by an example) what you are trying to do ? – hivert Feb 09 '14 at 08:47
  • Basically there's an input which needs to go through two filters: one for removing bad characters/phrases, one for changing misspelled words. I have the one for misspelled words done, but I don't know how to go about completely removing characters/phrases that come from a list such as: `["adf%","d@","z5","625","&55h"]` from the string `str = "dkj3n^3#$2kj3dx"` – derkyzer Feb 09 '14 at 08:52
  • 1
    Please don't write this in a comment but edit your post ! – hivert Feb 09 '14 at 09:00
  • Does it notify those who have commented or answered? I'm afraid if I do that that I won't get a response back. – derkyzer Feb 09 '14 at 09:03
  • Yes it does. Don't worry. – hivert Feb 09 '14 at 09:04
  • So any ideas? I'm clueless as to what to do here. – derkyzer Feb 09 '14 at 09:10

0 Answers0