Question: Python language 1. Write a function counts that accepts a list of integers and a set of integers as parameters and returns a dictionary from
Python language
1. Write a function counts that accepts a list of integers and a set of integers as parameters and returns a dictionary from each value in the set to the number of occurrences of that value in the list. For example, if your function is passed the following list and set as parameters: list: [4, -2, 3, 9, 4, 17, 5, 29, 14, 87, 4, -2, 100] set: [-2, 4, 29] Then your function should return the dictionary (-2:2, 4:3, 29:1}, because there are two occurrences of -2, three occurrences of 4, and one occurrence of 29. The order of the key/value pairs does not matter. Sample Run x= [4, -2, 3, 9, 4, 17,5, 29, 14, 87,4, -2, 100] y=[-2,4, 29] print(counts(x,y) {4:3, -2: 2, 29: 1}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
