315,373 views
16 votes
16 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.)

User Brian Moeskau
by
2.7k points

1 Answer

18 votes
18 votes

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

User Farm Ostrich
by
2.5k points