Dictionaries & Sets · Question 16 · Hard

An int, a float and a bool are used as keys in one dictionary literal. What does this print?

d = {1: "a", 1.0: "b", True: "c"}
print(len(d), d[1])
  1. 3 a
  2. 2 c
  3. 1 a
  4. 1 c
Answer and explanation

Answer: D. 1 c

Explanation: 1, 1.0 and True are equal and have the same hash, so they count as the same key. The dictionary ends up with one entry; the first key 1 is kept and its value is overwritten twice, ending as "c".

Previous: pop() is called for a key that exists and for one that does not. What does… · Next: Sets are built from the letters of two words. What is printed?

Practise dictionaries & sets

Try a fresh set of dictionaries & sets questions with an explanation after every answer, free and without signing up: Dictionaries & Sets practice. Or sit a full placement mock test.

More dictionaries & sets questions

More python practice

Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge