I need to create a word list from a text file. The list is going to be used in a hangman code and needs to exclude the following from the list:
- duplicate words
- words containing less than 5 letters
- words that contain 'xx' as a substring
- words that contain upper case letters
the word list then needs to be output into file so that every word appears on its own line. The program also needs to output the number of words in the final list.
This is what I have, but it's not working properly.
def MakeWordList():
infile=open(('possible.rtf'),'r')
whole = infile.readlines()
infile.close()
L=[]
for line in whole:
word= line.split(' ')
if word not in L:
L.append(word)
if len(word) in range(5,100):
L.append(word)
if not word.endswith('xx'):
L.append(word)
if word == word.lower():
L.append(word)
print L
MakeWordList()