Write a function assoc_list(l) that, given a list 1 , returns a list of tuples where the first integer represents the element of the int list i 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.) from functools import reduce def assoc_list (1): # YOUR CODE HERE result = assoc_list [1; 2; 2; 1; 3] result.sort(key=lambda x:x[0]) # sort the result list by the first element of a tuple. assert (result [(1,2), (2, 2), (3, 1)]). ==

Respuesta :

A for-loop can be used to iterate through a list of tuples. Utilize call list and the indexing syntax tuple[0] to access the first element of each tuple inside the for-loop.

What are the tuples, where is the first integer?

The tuple () function accepts an iterable as input and transforms it into a tuple object. The tuple() method can be used to convert a Python list to a tuple by passing the entire list as an argument, and it will output the tuple data type as an output.

Therefore, Index-0 will yield the first element in each tuple in a list, allowing us to iterate through the complete list of tuples and get first that way. To add each tuple's first element to the list, use append(object), where object is the tuple's first element.

Learn more about tuples here:

https://brainly.com/question/20982723

#SPJ1