127k views
0 votes
Write a function assoc_list(l) that, given a list l, returns a list of tuples where the first integer represents the element of the int list l and the second integer represents the number of occurrences of that element in the list. this associative list should not contain duplicates. order does not matter. for example, assoc_list [1, 2, 2, 1, 3] = [(2, 2), (1, 2), (3, 1)]. we recommend you to use the reduce function for this. (we had this problem before in assignment 2.)

1 Answer

1 vote

This associative list should not contain duplicates. Order does not matter. For example, assoc_list [1, 2, 2, 1, 3] [(2, 2)

User Robert Cutajar
by
4.5k points