(SOLVED)Code that rewrites a "split" text document with keys and values is giving random values to keys

A few months ago I was working on a project on Arduino to recreate a system from the 1960s used in bowling alleys to tell you where to aim. In the original patent(Its expired, don’t worry) which gave all of the pin combinations and the arrow that would light up, they were listed like “1-2-4-10” with the corresponding arrow to the right of it(“1-2”), which I wanted to convert to 0s and 1s(IE {1,1,0,1,0,0,0,0,0,1} with the arrow marked as “r1”) in the Arduino code. Since this contained 1000+ combinations, doing it manually would take ages, and so my friend created a code in python that would convert them all to the format I wanted it to.

I was getting ready to sell my product to someone, but realized after doing some testing that some of the pin combinations had the wrong arrow associated to them. My friend hasn’t been online recently, so I had to take matters into my own hands and after a bit of debugging I determined that it is randomly picking the arrow(value) choice for a few of the pin combinations(key). I put a choice that is only used once on the input side and it was nowhere in the output document. It even created two extra pin combinations/keys (1012 vs 1014).

Here is the code:

pathmap = {"1":"r2", "2":"b2", "3":"g1", "4":"p2", "1-2":"r1", "6":"y1", "7":"p1", "1-3":"r3", "2-4":"b1", "10":"y2", "3-6":"g2", "45":"g3"}

result = {}
with open("spare.txt", "r") as f:
    for line in f:
        data = line.split(" ")
        combo = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        for pin in data[0].split("-"):
            combo[int(pin) - 1] = 1
            result["{" + ", ".join(str(x) for x in combo) + "}"] = pathmap[data[1].strip()]

with open("result.txt", "w") as f:
    for key, value in result.items():
        f.write(key + "," + value + ",\n")

Here is a image of spare.txt with the arrow number that should be assigned to the 3 pin leave:
Input
And here is a image of the output, result.txt, which shows the same 3 pin leave getting a completely different arrow/value set to it than it should be getting:

I did print(combo) and saw that it was picking the same leave multiple times with a different arrow association/value each time.
Any help is appreciated as I am new to Python, I am just trying to get this working properly.

Looks like it depends on the input. If you have two input lines that will create different output for pin 3, only the last one will win.
3 45 by itself will create the correct output, but 3-5-6-8-10 3-6 being after will overwrite it and change the output to g2.

Without knowing the algorithm, there’s nothing to suggest. The python program is doing what it is asked, but I don’t know how that differs from your intent. I don’t see anything that suggests the output will be random, but if you’re making changes to spare.txt, the output will certainly change.

Alright I finally figured it out. I moved the result line out of the for pin loop so now it will only write a new key once the combo has been fully filled out. This fixed the problem.