dictionary with multiple values code example
Example 1: how to have multiple values to a key in dict in python
from collections import defaultdict
data = [(2010, 2), (2009, 4), (1989, 8), (2009, 7)]
d = defaultdict(list)
print (d)
for year, month in data:
d[year].append(month)
print (d)
Example 2: how to create multiple dictionaries in python
import string
for name in ["lloyd", "alice", "tyler"]:
name = {"name": string.capitalize(name), "homework": [], "quizzes": [], "tests": []}
Example 3: how to use multiple keys for single value in dictionary python
dict = {'a':'value1', 'b':'value2', 'c':'value 3'}
Example 4: multiple values in a dictionary python
a["abc"] = [1, 2, "bob"]