Question DSA-HASH-0042
MediumWhat is the output of this code?
from collections import defaultdict
words = ["eat", "tea", "tan", "ate", "nat", "bat"]
g = defaultdict(list)
for w in words:
g["".join(sorted(w))].append(w)
print(sorted(len(v) for v in g.values()))
- A.
[1, 1, 4]
- B.
[1, 2, 3]
- C.
[2, 2, 2]
- D.
[3, 3]
Sign up free to see the answer and a step-by-step explanation.