note to myself: set()s are much faster than list()s and auto-eliminate duplicates
This commit is contained in:
parent
aa29aaedd4
commit
8eecddaf60
13
day07.py
13
day07.py
@ -32,16 +32,15 @@ def getBagContent(bag_line):
|
|||||||
|
|
||||||
def getPossibleBagsForMyColor(color_dict, my_color):
|
def getPossibleBagsForMyColor(color_dict, my_color):
|
||||||
if my_color not in color_dict:
|
if my_color not in color_dict:
|
||||||
return []
|
return set()
|
||||||
|
|
||||||
color_list = color_dict[my_color]
|
color_set = set(color_dict[my_color])
|
||||||
for color in color_dict[my_color]:
|
for color in color_dict[my_color]:
|
||||||
extend_list = getPossibleBagsForMyColor(color_dict, color)
|
extend_set = getPossibleBagsForMyColor(color_dict, color)
|
||||||
for extra_color in extend_list:
|
for extra_color in extend_set:
|
||||||
if extra_color not in color_list:
|
color_set.add(extra_color)
|
||||||
color_list.append(extra_color)
|
|
||||||
|
|
||||||
return color_list
|
return color_set
|
||||||
|
|
||||||
|
|
||||||
def getBagContentCount(color_dict, my_color):
|
def getBagContentCount(color_dict, my_color):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user