AlgoMaster Logo

Sets - Quiz

Last Updated: January 3, 2026

Sets Exercises

28 quizzes

1
Code Completion

Complete the code to create a set of unique user IDs from the given list of IDs

python
1
unique_user_ids = (user_id_list)

Click an option to fill the blank:

2
Code Completion

Complete the code to check if a product code already exists in the inventory set

python
1
is_existing = 'P100' inventory_codes

Click an option to fill the blank:

3
Code Completion

Complete the code to get all unique tags used across two blog posts

python
1
all_tags = tags_post1 tags_post2

Click an option to fill the blank:

4
Multiple Choice

Which statement correctly creates an empty set of email addresses?

5
Multiple Choice

You have a set of usernames. Which property of sets is most useful to avoid duplicate registrations?

6
Multiple Choice

Which method would you use to add several new permissions from a list to an existing permissions set?

7
Multiple Choice

Which operation returns items that are in set_a but not in set_b?

8
Multiple Choice

You want to safely remove a user ID from a set without raising an error if it is missing. Which method should you use?

9
Multiple Choice

Which choice correctly describes a frozenset?

10
Multiple Choice

Which operation is valid on both set and frozenset objects?

11
Multiple Choice

You have two sets of attendees: morning_session and afternoon_session. Which operation gives attendees who joined both sessions?

12
Multiple Choice

What is the main benefit of using a frozenset as a dictionary key?

13
Multiple Choice

Which expression converts a string of tags into a set of unique characters?

14
Sequencing

Order the steps to collect unique error codes from a list and then check if a specific code is present.

Drag and drop to reorder, or use the arrows.

15
Sequencing

Order the steps to use a frozenset of allowed roles as a dictionary key for caching permissions.

Drag and drop to reorder, or use the arrows.

16
Output Prediction

What is the output of this code?

1tags = {'python', 'backend', 'api'}
2print('python' in tags)
17
Output Prediction

What is the output of this code?

1a = {1, 2, 3}
2b = {3, 4}
3print(a & b)
18
Output Prediction

What is the output of this code?

1emails = {'a@example.com', 'b@example.com'}
2emails.add('a@example.com')
3print(len(emails))
19
Output Prediction

What is the output of this code?

1numbers = {1, 2, 3, 4}
2removed = numbers.discard(5)
3print(numbers)
20
Output Prediction

What is the output of this code?

1features = frozenset(['login', 'signup', 'profile'])
2print('login' in features)
21
Bug Spotting

This function is supposed to remove a user from a set of active_users without raising an error if the user is not present. Find the bug.

Click on the line(s) that contain the bug.

python
1
def deactivate_user(active_users, user_id):
2
    if user_id not in active_users:
3
        active_users.remove(user_id)
4
    return active_users
22
Bug Spotting

This code tries to use a set of tags as a dictionary key for caching results. Find the bug.

Click on the line(s) that contain the bug.

python
1
def cache_result(cache, tags, result):
2
    key = set(tags)
3
    cache[key] = result
4
    return cache
23
Matching

Match each set method/operator with what it does in a notification system.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

24
Matching

Match each type with its correct description related to sets.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

25
Fill in the Blanks

Complete the code to build a set of unique visitors from a list, then freeze it for use as a dictionary key.

python
1
def freeze_unique_visitors(visitor_list):
2
unique_visitors = (visitor_list)
3
frozen_visitors = (unique_visitors)
4
return frozen_visitors

Click an option to fill blank 1:

26
Fill in the Blanks

Complete the code to add multiple new skills to a developer_skills set, then remove an obsolete skill safely.

python
1
def update_skills(developer_skills, new_skills):
2
developer_skills.(new_skills)
3
developer_skills.('flash')
4
return developer_skills

Click an option to fill blank 1:

27
Hotspot Selection

Click the line that attempts to modify an immutable frozenset of roles.

Click on the line to select.

python
1
roles = frozenset(['admin', 'editor'])
2
roles_set = {'viewer'}
3
roles_set.add('guest')
4
roles.add('guest')
28
Hotspot Selection

Click the line where a set is incorrectly used as a dictionary key.

Click on the line to select.

python
1
favorite_colors = {'red', 'blue'}
2
color_ratings = {}
3
color_ratings[favorite_colors] = 5
4
print(color_ratings)