โ† Python
#9 most askedVery commonMediumData types & mutability

How do dicts and sets work?

๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Why are dict lookups O(1)? What can be a dict key or set member?

๐Ÿ”ฎ Predict the output

seen = set()
seen.add((1, 2))
try:
    seen.add([1, 2])
except TypeError as e:
    print("error:", e)
print((1, 2) in seen, len({1: "a", 1.0: "b", True: "c"}))

๐ŸŽค Answer it out loud, then check yourself

Say your answer as if the interviewer is listening (30โ€“90 seconds). Then reveal what a strong answer covers and tick what you said.

    Answer out loud first, then compare.
    Want to rehearse it?
    Answer this to the AI interviewer and get a verdict โ†’