<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Day 7
Problem 1
How many bag colors can eventually contain at least one shiny gold bag?
Step1:  Problem 2
How many individual bags are required inside your single shiny gold bag?
<ASSISTANT_TASK:>
Python Code:
from collections import defaultdict
dict_of_colors = defaultdict(list)
with open('input.txt', 'r') as fd: 
    for line in fd: 
        if 'no other bags' not in line: 
            sentence = line.split(' ')
            main_color = ' '.join(line.split(' ')[:2])
            for i, word in enumerate(sentence): 
                if word.isdigit(): 
                    dict_of_colors[main_color] += [' '.join([sentence[i + 1], sentence[i + 2]])]
def pokemon_games_finder(bags, dict_of_colors):
    for outside_color, inside_colors in dict_of_colors.items(): 
        for color in inside_colors: 
            if color in good_bags: 
                bags.add(outside_color)
                
    return bags
my_color = 'shiny gold'
good_bags = set([my_color])
n_good_bags = []
for i in range(0, 10):
    good_bags = pokemon_games_finder(good_bags, dict_of_colors)
    if len(n_good_bags) > 2 and len(good_bags) == n_good_bags[i - 1]: 
        break
    n_good_bags.append(len(good_bags))
len(good_bags) - 1 # includes my_color
Explanation: Day 7
Problem 1
How many bag colors can eventually contain at least one shiny gold bag?
End of explanation
dict_of_n = defaultdict(dict)
with open('input.txt', 'r') as fd: 
    for line in fd: 
        if 'no other bags' not in line: 
            sentence = line.split(' ')
            main_color = ' '.join(line.split(' ')[:2])
            for i, word in enumerate(sentence): 
                if word.isdigit(): 
                    dict_of_n[main_color][' '.join([sentence[i + 1], sentence[i + 2]])] = int(word)
        else: 
            main_color = ' '.join(line.split(' ')[:2])
            dict_of_n[main_color] = 0
total_bags = 0
for bag1, count1 in dict_of_n[my_color].items():
    total_bags += count1
    if dict_of_n[bag1] != 0:
        for bag2, count2 in dict_of_n[bag1].items():
            count2 = count1 * count2
            total_bags += count2
            if dict_of_n[bag2] != 0: 
                for bag3, count3 in dict_of_n[bag2].items():
                    count3 = count2 * count3
                    total_bags += count3
                    if dict_of_n[bag3] != 0: 
                        for bag4, count4 in dict_of_n[bag3].items():
                            count4 = count3 * count4
                            total_bags += count4
                            if dict_of_n[bag4] != 0: 
                                for bag5, count5 in dict_of_n[bag4].items():
                                    count5 = count4 * count5
                                    total_bags += count5
                                    if dict_of_n[bag5] != 0: 
                                        for bag6, count6 in dict_of_n[bag5].items(): 
                                            count6 = count5 * count6
                                            total_bags += count6
total_bags
Explanation: Problem 2
How many individual bags are required inside your single shiny gold bag?
End of explanation
<END_TASK>