I am trying to create a function that takes a string as an argument and returns a list of all of the generated words by swapping a letter with its immediate neighbor.
I first take each letter and create a list of strings and each string contains one letter.
Then I iterate through the new list of letters and try to swap them.
Then I join the letters together to form a string.
Then I append the new string to the list that I return.
Here is my code. Please tell me how to fix it. I don't want it to display the passed word in the list. Thank you.
def mixedString(word):
word = word.lower()
letters = []
newArray = []
for n in word:
letter = f"{n}"
letters.append(letter)
newList = []
for i in range(len(letters)):
newWord = ""
newArray = letters[i:] + letters[:i]
newWord = "".join(newArray)
newList.append(newWord)
return newList
myWord = "Dog"
print(mixedString(myWord))