Reuven M. Lerner @lernerpython.com · 20d

Want to create a dict of lists in #Python? Use setdefault: places = {} while True: city, country = input('Place: ').split() places.setdefault(country, []) # new country? set value to [] places[country].append(city) # list is guaranteed print(places)

2 likes 0 replies

?