A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-135.py
1d={}
2forcin"abca":
3d.setdefault(c,[]).append(1)
4print({k:len(v)fork,vind.items()})
Mutability
Answer & explanation
Console output
{'a': 2, 'b': 1, 'c': 1}
Why
setdefault either inserts a fresh [] for a new key or returns the existing list for a seen key. As we iterate "abca", 'a' is encountered twice and both times appends to the same list, giving it length 2, while 'b' and 'c' each appear once. dicts preserve insertion order, so the result keys read a, b, c.