Python: how do I create a list of combinations from a series of ranges of numbers
Question: For a list of numerical values of n length, e. g. `[1, 3, 1, 2, ...]`, I would
like to create a list of the lists of all possible combinations of values from
`range[x+1]` where x is a value from the list. The output might look something
like this:

    
    
    for list[1, 3, 2] return all possible lists of range[x+1] values:
        # the sequence of the list is unimportant
    [
    [0,0,0],[1,0,0],[0,1,0],[0,2,0],[0,3,0],[0,0,1],[0,0,2],[1,1,0],
    [1,2,0],[1,3,0],[1,0,1],[1,0,2],[0,1,1],[0,2,1],[0,3,1],[0,1,2],
    [0,2,2],[0,3,2],[1,1,1],[1,2,1],[1,3,1],[1,1,2],[1,2,2],[1,3,2]
    ]
    

So in this example I am looking for all variations of `[e1, e2, e3]` from `e1
in [0,1], e2 in [0,1,2,3] and e3 in [0,1,2]`


Answer: Python's itertools module has a tool that does what you need:

    
    
    import itertools
    p = itertools.permutations([0, 1, 2, 3])
    p_as_list = list(p)
    

Edit: As your needs are fairly specific you could benefit from having your own
function that does something alike this one: (note I haven't got the
implementation down just yet, maybe someone might refine this):

    
    
    def magic_permutations (*args):
        lists = []
        larg = len(args)
        for i in range(larg):
            lists.append([])
        i = 0
        for nums in args: 
            for num in nums:
                if i >= larg:
                    i = 0
                lists[i].append(num)
                i += 1
        return lists
    

Edit: I misunderstood your question the first time, so I'll apologize for
that. I'll however leave this be.

