Complete the code to create a tuple with three elements.
my_tuple = (1, 2, [1])
The tuple elements are separated by commas and enclosed in parentheses. The third element should be the integer 3.
Complete the code to compare if a tuple and a list with the same elements are equal.
result = (1, 2, 3) [1] [1, 2, 3]
Using == compares the values and order of elements. A tuple and a list with the same elements in the same order are not equal because they are different types.
Fix the error in the code to convert a list to a tuple.
my_list = [1, 2, 3] my_tuple = [1](my_list)
The tuple() function converts an iterable like a list into a tuple.
Fill both blanks to create a dictionary comprehension that maps each index to its tuple element.
my_tuple = (10, 20, 30) index_map = [1]: [2] for [1], [2] in enumerate(my_tuple)
In the comprehension, 'index' is the dictionary key and 'value' is the tuple element.
Fill all three blanks to create a list of tuples from a list of lists.
list_of_lists = [[1, 'a'], [2, 'b'], [3, 'c']] list_of_tuples = [([1], [2]) for [3] in list_of_lists]
We unpack each 'item' from the list_of_lists and create a tuple with its first and second elements.