Question 12 Not complete Marked out of 7.00 Flag question Write a function inverted_word_counts (word_count_dict, banned
Posted: Fri Jun 10, 2022 11:55 am
Question 12 Not complete Marked out of 7.00 Flag question Write a function inverted_word_counts (word_count_dict, banned) that takes as a parameter a dictionary mapping from words to word-counts (like the ones in earlier questions) and a list of banned words, then returns the dictionary inverted, i.e. mapping from an integer word count to an alphabetically ordered list of words with that count but skipping words that are banned. For example, if the word count dictionary were: {'a': 20, 'west': 10, 'blotto': 1, 'bingo':1, 'x': 5, 'member': 1} and the banned list = ["member", "west"] then the inverted dictionary would be {1: ['bingo', 'blotto'], 5: ['x'], 20: ['a']} showing that the list of words occurring exactly once is ['bingo', 'blotto'] (note that it's alphabetically ordered), the list of words occurring five times is just 'x' and the list of words occurring 20 times is ['a']. For example: Test Result test dict= {'a': 20, 'west': 10, 'blotto': 1, 'bingo':1, 'x': 5, 'member': 1) 1: ['bingo', 'blotto'] banned = ["member", "west"] 5: ['x'] inverse inverted_word_counts (test_dict, banned) 20: ['a'] for count in sorted (inverse.keys()): print('{}: {}'.format(count, inverse [count])) Answer: (penalty regime: 0, 10, 20, ... %) 1def inverted_word_counts(word_count_dict, banned): """Takes as a parameter a dictionary mapping from words to word-counts and a list of banned words, then returns the dictionary inverted.""" H23