I have a long dictionary of elements and I want to delete any dictionary words that have only a list of 1 element. for instance
wordDict={'aardvark':['animal','shell'], 'bat':['animal', 'wings'],
'computer':['technology'], 'donut':['food','sweet']}
I want to delete the entry "computer", because there is only one element in it. I started by iterating through wordDict and putting each entry in the dictionary on a separate list so that it looks like this:
wordList=[['animal','shell'],['animal','wings'],['technology'],['food','sweet']]
and then repeat this list backward, checking to see if each item in the list is longer than 1. Backward, because going forward causes the index to change when it is deleted.
So, in wordList ['technology'] is deleted and that is what remains
wordList=[['animal','shell'],['animal','wings'],['food','sweet']]
The problem is that since wordDict gets significantly larger (100k + words), it takes a lot of time to put wordDict in a list and then iterate over that list, and I want to make it more efficient.
I thought about iterating through the dictionary backwards, checking to see if each entry has multiple words, and then deletes the dictionary entry if it is not. In the end, what needs to be returned is a list, not a dictionary, so the index does not matter at the end, I used them only for sorting.
Is there any way to do this?