Iterating through compound tags

I'm currently trying to make a data-driven card game, and have a big registry in the form of a compound tag, where keys are card IDs and values are smaller compound tags that hold the data for the card, including its weight when being pulled When pulling a random card, you'd have to look through each individual registry key, check the weight of that card, and then add it to a counter so you can pick a number below it with /random, then iterate through the whole thing again with the whole thing again while ticking the random number down so you can pick the card you land on when the number hits 0. Hope that made sense. The issue is i don't know how to do the iteration Currently my very ugly solution to this is to have a big python-program-generated list you generate alongside the compound with each card ID in it x times, x being the weight. Very unappealing but it works for debugging, how do I make it an upgrade?

Continue to help post