I'm trying to create a function that takes in a list and then edits the list as per a prior filter function (isValid) and also convert all words in the list into lowercase. Any words that don't fit the definition should be removed from the list.
The program works well when I return the edited list in cleanWords(), but the criteria do not allow me to use a return statement. When I don't return anything, the list that should be inputted into countFrequencies creates a "TypeError: 'NoneType' object is not iterable".
Could I then create a new function and pass the list through each argument separately? Or is there any other way of getting around this?
def cleanseWords(listOfWords):
for i in range(len(listOfWords)-1,-1,-1):
listOfWords[i] = listOfWords[i].lower()
if not isValid(listOfWords[i]):
listOfWords.remove(listOfWords[i])
def countFrequencies(listOfWords):
word_dict = {}
for word in listOfWords:
if word in word_dict:
word_dict[word] += 1
else:
word_dict[word] = 1
return word_dict
print(countFrequencies(cleanseWords(['aaaaaa','bbbbbb','cccc'])))