Slide 51
Slide 51 text
51
from
collections
import
defaultdict
items
=
["a",
"b",
"a",
"x",
"x",
"y",
"c",
"c",
"a"]
item_counts
=
defaultdict(int)
for
i
in
items:
item_counts[i]
=
item_counts[i]
+
1
defaultdict(int,
{'a':
3,
'b':
1,
'c':
2,
'x':
2,
'y':
1})
Using defaultdict