0
0
Pythonprogramming~20 mins

Subset and superset checks in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Subset and Superset Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this subset check?
Consider the following Python code:
set_a = {1, 2, 3, 4}
set_b = {2, 3}

What is the output of set_b.issubset(set_a)?
Python
set_a = {1, 2, 3, 4}
set_b = {2, 3}
print(set_b.issubset(set_a))
ATrue
BFalse
CTypeError
DNone
Attempts:
2 left
๐Ÿ’ก Hint
Remember, a subset means all elements of one set are in the other.
โ“ Predict Output
intermediate
2:00remaining
What does this superset check return?
Look at this code:
set_x = {5, 6, 7, 8}
set_y = {6, 7}

What is the output of set_x.issuperset(set_y)?
Python
set_x = {5, 6, 7, 8}
set_y = {6, 7}
print(set_x.issuperset(set_y))
ATrue
BKeyError
CFalse
DNone
Attempts:
2 left
๐Ÿ’ก Hint
Superset means the first set contains all elements of the second.
โ“ Predict Output
advanced
2:00remaining
What is the output of this subset check with an empty set?
Given:
set_m = set()
set_n = {1, 2, 3}

What does set_m.issubset(set_n) print?
Python
set_m = set()
set_n = {1, 2, 3}
print(set_m.issubset(set_n))
AFalse
BTrue
CTypeError
DNone
Attempts:
2 left
๐Ÿ’ก Hint
Think about whether an empty set is a subset of any set.
โ“ Predict Output
advanced
2:00remaining
What does this superset check return?
Look at this code:
set_a = {1, 2, 3}
not_a_set = [1, 2]

What happens when running set_a.issuperset(not_a_set)?
Python
set_a = {1, 2, 3}
not_a_set = [1, 2]
print(set_a.issuperset(not_a_set))
AAttributeError
BFalse
CTrue
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
issuperset accepts any iterable, not just sets.
๐Ÿง  Conceptual
expert
3:00remaining
Which option shows the correct way to check if set A is a strict subset of set B?
You want to check if set A is a subset of set B but not equal to B. Which code snippet does this correctly?
Aset_a.issuperset(set_b)
Bset_a <= set_b
Cset_a.issubset(set_b) and set_a != set_b
Dset_a < set_b
Attempts:
2 left
๐Ÿ’ก Hint
Python has operators for strict subset and subset or equal.