0
0
Pythonprogramming~10 mins

Frozen set behavior in Python - Interactive Code Practice

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

Complete the code to create an immutable set using the correct function.

Python
my_set = [1]([1, 2, 3])
print(my_set)
Drag options to blanks, or click blank then click option'
Aset
Bfrozenset
Clist
Dtuple
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using set() instead of frozenset() which creates a mutable set.
Using list() or tuple() which are not sets.
2fill in blank
medium

Complete the code to check if an element exists in a frozen set.

Python
fset = frozenset([10, 20, 30])
if [1] in fset:
    print("Found")
else:
    print("Not found")
Drag options to blanks, or click blank then click option'
A20
B15
C25
D40
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Checking for a number not in the frozen set, which results in "Not found".
Using a variable name instead of a value.
3fill in blank
hard

Fix the error in the code by choosing the correct method to add an element to a frozen set.

Python
fset = frozenset([1, 2, 3])
fset = fset.[1]([4])
print(fset)
Drag options to blanks, or click blank then click option'
Aadd
Binsert
Cunion
Dappend
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Trying to use add() or append() which do not work on frozen sets.
Using insert() which is not a set method.
4fill in blank
hard

Fill both blanks to create a frozen set from a list and check if it is a subset of another frozen set.

Python
fset1 = frozenset([1])
fset2 = frozenset([1, 2, 3, 4, 5])
print(fset1.[2](fset2))
Drag options to blanks, or click blank then click option'
A[1, 2, 3]
B(1, 2, 3)
Cissubset
Dissuperset
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a tuple instead of a list to create the frozen set.
Using issuperset() which checks the opposite relation.
5fill in blank
hard

Fill all three blanks to create a frozen set, add elements using union, and check the length.

Python
fset = frozenset([1])
fset = fset.[2]([3])
print(len(fset))
Drag options to blanks, or click blank then click option'
A[10, 20]
Bunion
Cfrozenset([30, 40])
Dadd
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Trying to use add which does not work on frozen sets.
Passing a list directly to union instead of a frozen set.