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