<jupyter_start><jupyter_text>Make it a function<jupyter_code>def position_product(list_input):
    #adapted from https://stackoverflow.com/questions/3199171/append-multiple-values-for-one-key-in-a-dictionary
    from collections import defaultdict
    move_dict = defaultdict(list)
    for line in list_input:
        key = line.split()[0]
        val = int(line.split()[1])
        move_dict[key].append(val)
    move_sums = {k:sum(move_dict[k]) for k in move_dict.keys()}
    result = move_sums['forward']*(move_sums['down']-move_sums['up'])
    print('Moves forward: ', move_sums['forward'])
    print('Moves down: ', move_sums['down'])
    print('Moves up: ', move_sums['up'])
    print('Final position (x,y): ', move_sums['forward'],',',move_sums['down']-move_sums['up'])
    print('Product of vertical and horizontal position: ', result)
    return result
    
position_product(lines)<jupyter_output>Moves forward:  1931
Moves down:  1983
Moves up:  1030
Final position (x,y):  1931 , 953
Product of vertical and horizontal position:  1840243<jupyter_text>Part TWO<jupyter_code>def position_product_2(list_input, verbose = None):
    aim        = 0
    horizontal = 0
    depth      = 0
    for line in list_input:
        print(line) if verbose else None
        move = line.split()[0]
        X    = int(line.split()[1])
        if move == 'forward':
            horizontal += X
            depth += (aim*X)
        elif move == 'down':
            aim += X
            #depth += X
        elif move == 'up':
            aim -= X
            #depth -= X
        print('Aim: ',aim,' Depth: ',depth,' Horizontal: ',horizontal) if verbose else None
    result = horizontal*depth
    print('Final params: Aim: ',aim,' Depth: ',depth,' Horizontal: ',horizontal)
    print('Result: ',result)
    return result
    
with open("test_input2.txt", "r") as tf:
    test = tf.read().split('\n')
print(test)
position_product_2(test,verbose = True)
position_product_2(lines)<jupyter_output>Final params: Aim:  953  Depth:  894762  Horizontal:  1931
Result:  1727785422
{'fraction_non_alphanumeric': 0.1396702230843841, 'fraction_numerical': 0.03249272550921436, 'mean_word_length': 3.2016293279022405, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '211249', 'license': 'MIT', 'n_tokens_mistral': 717, 'n_tokens_neox': 668, 'n_words': 162, 'path': 'day2.ipynb', 'repo_name': 'leakp/advent-of-code', 'size': '2062'}