I am using gambit in python to simulate a world in a game theoretic manner. One construct of gambit is to save the "outcomes" for a set of decisions each player involved takes. This is of the form:
game[d1,d2,d3,...,dn][n] = payoff
where d1 is the index of decision made by player 1, d2 is the index of decision made by player 2, and so on and n is the index of the player for whom the payoff is being stored.
Now, there may be variable number of players, so the dimension of the index passed into the game object may change
how do I generate the series from [0,0,...,0] through [8,8,...,8] (where dimension = number of players = n) so that I can store them into [d1,d2,d3,...,dn]?
Take a look at python's
itertoolsmodule. It sounds like theproductfunction will do what you want.Example:
Gives all lists of length three with two elements
There's lots of other possibilities with
itertools, in particular it also providespermutationsandcombinations.