makes parsing minimally faster (and also more readable)
This commit is contained in:
parent
29b0604952
commit
9b0b8eb1f6
7
day07.py
7
day07.py
@ -21,11 +21,8 @@ def getBagContent(bag_line):
|
|||||||
return return_dict
|
return return_dict
|
||||||
|
|
||||||
for content in contents.split(", "):
|
for content in contents.split(", "):
|
||||||
match_groups = re.match(content_re, content)
|
content_count, content_color = re.match(content_re, content).groups()
|
||||||
if not match_groups:
|
return_dict[color][content_color] = int(content_count)
|
||||||
print("ERROR: content '%s' cannot be matched" % content)
|
|
||||||
|
|
||||||
return_dict[color][match_groups.group(2)] = int(match_groups.group(1))
|
|
||||||
|
|
||||||
return return_dict
|
return return_dict
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user