-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?
'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?
– Vinicius Bussola
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!
– Willian Freitas