0
0
Pythonprogramming~10 mins

Tuple vs list comparison in Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a tuple with three elements.

Python
my_tuple = (1, 2, [1])
Drag options to blanks, or click blank then click option'
A3
B[3]
C{3}
D"3"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets [] which create a list instead of a tuple.
Using curly braces {} which create a set or dictionary.
Putting the number inside quotes which makes it a string.
2fill in blank
medium

Complete the code to compare if a tuple and a list with the same elements are equal.

Python
result = (1, 2, 3) [1] [1, 2, 3]
Drag options to blanks, or click blank then click option'
A>
B!=
C<
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using != which checks for inequality.
Using < or > which compare order but are not suitable here.
3fill in blank
hard

Fix the error in the code to convert a list to a tuple.

Python
my_list = [1, 2, 3]
my_tuple = [1](my_list)
Drag options to blanks, or click blank then click option'
Atuple
Bdict
Cset
Dlist
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using list() which returns a list, not a tuple.
Using set() which creates a set, not a tuple.
Using dict() which creates a dictionary, not a tuple.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each index to its tuple element.

Python
my_tuple = (10, 20, 30)
index_map = [1]: [2] for [1], [2] in enumerate(my_tuple)
Drag options to blanks, or click blank then click option'
Avalue
Bindex
Ckey
Ditem
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Swapping key and value in the dictionary comprehension.
Using variable names not matching the unpacking from enumerate.
5fill in blank
hard

Fill all three blanks to create a list of tuples from a list of lists.

Python
list_of_lists = [[1, 'a'], [2, 'b'], [3, 'c']]
list_of_tuples = [([1], [2]) for [3] in list_of_lists]
Drag options to blanks, or click blank then click option'
Aitem[0]
Bitem[1]
Citem
Delement
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using wrong variable names in the comprehension.
Not accessing elements by index correctly.