Question: Write a function named counter_dict that takes input a list. * returns a dictionary whose keys are the set of elements of the input
Write a function named counter_dict that takes input a list. * returns a dictionary whose keys are the set of elements of the input list and the values are number of occurences of that key in the input list. For example, if the input list is ['Paris', 'London', 'Moscow', 'London', 'Helsinki', 'London', 'Paris'] the counter_dict function should return {'Paris': 2, 'London': 3, 'Helsinki': 1, 'Moscow'; 1). Notes: Of course, ordering of the items in the dictionary is not important. [5]: my_travels = ['Paris', 'London', 'Moscow', 'London', 'Helsinki', 'London' -, 'Paris'] def counter_dict (input): # Do the job here pass #Call the function and see if it works counter_dict (my_travels)
Step by Step Solution
There are 3 Steps involved in it
Heres the implementation of the counterdict function python ... View full answer
Get step-by-step solutions from verified subject matter experts
