Skip to content
RED SAG Skills
easy5 pts · first answer countspythoncollections

Grouping values with defaultdict

What does this code print?

from collections import defaultdict

orders = [("Pune", 120), ("Delhi", 80), ("Pune", 50)]
by_city = defaultdict(list)
for city, amount in orders:
    by_city[city].append(amount)
print(dict(by_city))
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions