I wrote a Python for loop that goes through each word in the English language (from nltk.corpus import words), and prints words made only of 6 letters provided by the user. The 6 user inputs are stored in a list named characters, so the for loop compares the items from the list to each string (english words).
The problem is that words are printed that contain multiple characters of the same character. For example, if the characters are 'u, l, c, i , e, n', words with multiple letters such as "icicle" are returned. How to I prevent the script from returning words with duplicate letters?
characters = [input1, input2, input3, input4, input5, input6]
for word in word_list:
word = word.lower()
if len(word) == 3:
if word[0] in characters and word[1] in characters and word[2] in characters:
print(word)
elif len(word) == 4:
if word[0] in characters and word[1] in characters and word[2] in characters and word[3] in characters:
print(word)
elif len(word) == 5:
if word[0] in characters and word[1] in characters and word[2] in characters and word[3] in characters and word[4] in characters:
print(word)
elif len(word) == 6:
if word[0] in characters and word[1] in characters and word[2] in characters and word[3] in characters and word[4] in characters and word[5] in characters:
print(word)
I know the code is inefficiently written, so I'd appreciate tips on improvement as well. An example of the results of the above script is:
eel
eileen
eli
ell
elle
ellen
ellice
encell
ennui
eunice
ice
iceni
icicle
ilicic
ilicin
ill
inn
inulin