Skip to content

Commit da99c79

Browse files
drvinceknightmarcharper
authored andcommitted
Use defaultdict.
1 parent 1cbd71a commit da99c79

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

axelrod/interaction_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
This is used by both the Match class and the ResultSet class which analyse
88
interactions.
99
"""
10-
from collections import Counter
10+
from collections import Counter, defaultdict
1111
import csv
1212
import tqdm
1313
import pandas as pd
@@ -251,14 +251,11 @@ def read_interactions_from_file(filename, progress_bar=True):
251251
if progress_bar:
252252
groupby = tqdm.tqdm(groupby)
253253

254-
pairs_to_interactions = {}
254+
pairs_to_interactions = defaultdict(list)
255255
for _, d in tqdm.tqdm(groupby):
256256
key = tuple(d[["Player index", "Opponent index"]].iloc[0])
257257
value = list(map(str_to_actions, zip(*d["Actions"])))
258-
try:
259-
pairs_to_interactions[key].append(value)
260-
except KeyError:
261-
pairs_to_interactions[key] = [value]
258+
pairs_to_interactions[key].append(value)
262259
return pairs_to_interactions
263260

264261

0 commit comments

Comments
 (0)