Single answer

A fruit stall updates its stock dictionary. What does this program print?

stock = {"apples": 3}
stock["pears"] = 5
stock["apples"] = 10
print(stock)
Single answer

What does this program print?

prices = {"apple": 2.5}
print(prices.get("kiwi"), prices.get("kiwi", 0))
print(prices["kiwi"])
Single answer

A museum logs visitor names at the entrance. What does this program print?

visitors = ["ana", "dan", "ana", "Ana", "dan"]
print(len(set(visitors)))
Single answer

Two shift lists are compared with set operators. What does this program print?

monday = {"ana", "dan", "ion"}
tuesday = {"dan", "ion", "eva"}
print(sorted(monday & tuesday), sorted(monday - tuesday), sorted(monday ^ tuesday))
Multiple answers

Which of these values can be used as a dictionary key? Select all that apply.

Single answer

What does this loop print?

ages = {"ana": 31, "dan": 27}
for item in ages:
    print(item)
Single answer

A word counter uses get with a default. What does this program print?

words = "to be or not to be".split()
counts = {}
for w in words:
    counts[w] = counts.get(w, 0) + 1
print(counts)
Single answer

True or false: the expression {} creates an empty set.

Single answer

A shop tries to remove products that are out of stock. What happens when this program runs?

stock = {"apples": 0, "pears": 4, "plums": 0}
for fruit in stock:
    if stock[fruit] == 0:
        del stock[fruit]
print(stock)
Single answer

An app merges default settings with a user's choices using the | operator (Python 3.9 and later). What does this program print?

defaults = {"theme": "light", "lang": "en"}
user = {"lang": "ro"}
settings = defaults | user
print(settings, defaults)