Generate all possible letter exchanges in a word

Asked

Viewed 69 times

-1

I need to create a function that manages all possible letter exchanges that generate words with the same sound:

Palavra: Feijoada
Possibilidades: Feigoada, Feyjoada, Feijoada, Feygoada 

But I’m not able to do that, my function returns only one word:

Feigoada    

Code:

word = input()
word = word.lower()
cont = 0

letterlist = []
wordslist = []

for letter in word:
    letterlist.append(letter)
while cont < 6:
    if "c" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "c":
                letter = "k"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "k" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "k":
                letter = "c"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "m" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "m":
                letter = "n"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "n" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "n":
                letter = "m"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "j" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "j":
                letter = "g"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "g" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "g":
                letter = "j"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)
    cont += 1

What could I be missing from this code? Is there a library that already does this work?

  • 1

    'Feijoada' and 'Feigoada' do not have the same sound.. This change from J to G should be implemented only if the letter comes before 'e' or 'i', not?

  • I had done only with a few letters initially. I had not stopped to think about the G and J’s OK. Thank you so much for the tip!

1 answer

0


  • In the code there are only the treatments for the letters (C and K), (M and N) and (J and G). There is no treatment for (I and Y) for example. You need to create it.
  • Other details, you cannot trade J for G in all words.. only those that have and or i after the letter... Feijoada does not have the same sound as Feigoada.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.