In this code, I am trying to remove values (synonyms) within a list that are 7 or fewer characters from the dictionary. For some reason, my code is only partially removing the values that are 7 or fewer characters. Also, please do not remove any of the functions or use imports and sets to solve and keep the current code as intact as possible.
My current output:
{'show': ['exhibit', 'note', 'point to', 'indicate', 'reveal', 'demonstrate'], 'slow': ['unhurried', 'leisurely', 'behind', 'slack'],
'dangerous': ['perilous', 'hazardous', 'uncertain']}
Desired output:
{'show' : ['demonstrate', 'indicate', 'point to'],
'slow' : ['leisurely', 'unhurried'],
'dangerous' : ['hazardous', 'perilous', 'uncertain']}
word_dict = {'show': ['display', 'exhibit', 'convey', 'communicate', 'manifest', 'disclose'],
'slow': ['unhurried', 'gradual', 'leisurely', 'late', 'behind', 'tedious', 'slack'],
'dangerous': ['perilous', 'hazardous', 'uncertain']}
def main():
edited_synonyms = remove_word(word_dict)
print(edited_synonyms)
def remove_word(word_dict):
for key, value in word_dict.items():
for item in value:
if len(item) <= 7:
value.remove(item)
return word_dict
main()