In Python, I have a dictionary where the key is the stem and the value is a list of words with that stem, like this:
d= {‘achiev’: [‘achieved’, ‘achieve’] ‘accident’: [‘accidentally’, ‘accidental’] … } #over 1000 items in the dictionary.
How can I do for the 25 dictionary entries with the longest lists, print the stem and its list.
Thank you!
d = {'achiev': ['achieved', 'achieve'], 'accident': ['accidentally', 'accidental']} # over 1000 items in the dictionary. longest_list_stem = None for stem, lst in d.items(): if longest_list_stem is None or len(lst) > len(d[longest_list_stem]): longest_list_stem = stem print("Stem is", longest_list_stem) print("It's list is", d[longest_list_stem])
Get Answers For Free
Most questions answered within 1 hours.