Question 12 Not complete Marked out of 7.00 Flag question Write a function inverted_word_counts (word_count_dict, banned

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
correctanswer
Posts: 43759
Joined: Sat Aug 07, 2021 7:38 am

Question 12 Not complete Marked out of 7.00 Flag question Write a function inverted_word_counts (word_count_dict, banned

Post by correctanswer »

Question 12 Not Complete Marked Out Of 7 00 Flag Question Write A Function Inverted Word Counts Word Count Dict Banned 1
Question 12 Not Complete Marked Out Of 7 00 Flag Question Write A Function Inverted Word Counts Word Count Dict Banned 1 (135.35 KiB) Viewed 66 times
Help in Python 3
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
Register for solutions, replies, and use board search function. Answer Happy Forum is an archive of questions covering all technical subjects across the Internet.
Post Reply