note to myself: set()s are much faster than list()s and auto-eliminate duplicates

This commit is contained in:
Stefan Harmuth 2020-12-07 10:35:09 +01:00
parent aa29aaedd4
commit 8eecddaf60

View File

@ -32,16 +32,15 @@ def getBagContent(bag_line):
def getPossibleBagsForMyColor(color_dict, my_color):
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]:
extend_list = getPossibleBagsForMyColor(color_dict, color)
for extra_color in extend_list:
if extra_color not in color_list:
color_list.append(extra_color)
extend_set = getPossibleBagsForMyColor(color_dict, color)
for extra_color in extend_set:
color_set.add(extra_color)
return color_list
return color_set
def getBagContentCount(color_dict, my_color):