Chapter Practice Arena
All ChaptersWorking with Collections Problems
Targeted practice challenges specifically curated for this chapter. Inspect hints, verify outputs, and check Pythonic solutions.
Difficulty:
Chapter:
Showing 6 challenges · 20 total · Page 1 of 4
Start with user = {'name': 'Ari'}. Add the key 'active' with the value True, then update the name to 'Riya'. Print the final dictionary.
Starter Code
# Start with the provided dictionary
Expected Output:{'name': 'Riya', 'active': True}
Create the sets {2, 4, 6} and {4, 6, 8}. Print their common elements in ascending order.
Starter Code
# Create the sets and find their intersection
Expected Output:[4, 6]
Create numbers = [4, 8, 12] and print the middle element using its index.
Starter Code
numbers = [4, 8, 12] # Print the middle element
Expected Output:8
Given prices = {'pen': 10, 'book': 50}, use a for loop and items() to print each item name followed by its price, separated by one space.
Starter Code
prices = {'pen': 10, 'book': 50}
# Loop through the key-value pairs
Expected Output:pen 10
book 50
Start with ['red', 'green', 'blue']. Remove the last element using pop(), store the returned value in removed, then print removed and the updated list on separate lines.
Starter Code
# Use pop() and print the returned value and list
Expected Output:blue
['red', 'green']
Create a list containing 3 and 6. Append 9 to the list and print the updated list.
Starter Code
# Create the list and append 9
Expected Output:[3, 6, 9]