Best way to go about DRY?

Don’t repeat yourself, right?

Maybe it’s early but I’m having a tough time wrapping my mind around all the permutations I want to do with player data.
The following represents payload variables for API requests.

    rated_wins_as_white_19 = {
                'ordering':'-id',
                'width':'19',
                'height':'19',
                'white':'1403',
                'ranked':'true',
                'annuled':'false',
                'white_loses':'false',
                'black_loses':'true',
           }
rated_losses_as_white_19 = {
                'ordering':'-id',
                'width':'19',
                'height':'19',
                'white':'1403',
                'ranked':'true',
                'annuled':'false',
                'white_loses':'true',
                'black_loses':'false',
           }
rated_wins_as_black_19 = {
                'ordering':'-id',
                'width':'19',
                'height':'19',
                'black':'1403',
                'ranked':'true',
                'annuled':'false',
                'white_loses':'true',
                'black_loses':'false',
           }
rated_wins_as_black_19 = {
                'ordering':'-id',
                'width':'19',
                'height':'19',
                'black':'1403',
                'ranked':'true',
                'annuled':'false',
                'white_loses':'false',
                'black_loses':'true',
           }

I can brute force my way through it. It is an issue of copy, paste, and adjust but I code so I don’t have to do that.

Right now, I will probably make all the payload permutations in a dictionary and iterate through them unless somebody here has a better idea.

Based on what I see, you have 5 (really 4) independent attributes, 2 (really 3) dependent attributes, and 2 fixed attributes.

I’d put board size in one list, color in another, and wins/loses in the third. I’d only go with a dictionary if the full order is important. I would then calculate the rest.

1 Like

I’m looking at this and thinking that it might be better to just pull all my games and iterate entirely within Python instead of multiple permutations of API requests. I can work through everything I want in a single easy to read iteration. The path I’m on now is not easy to read.

100 at a time… Less than 500 games… Page through it and do it.