Possible values for each set of Python variables

1

Use Python 2.7

I have 5 variables: Fillrate, eCPM, Revenue, Impresiones y Oportunidades .

Each one can take the values:

ALERTA, Down, Estable, Up, Incremento

I need to know what options there may be for each set of variables. I mean something like this:

["Estable","Estable","Estable","Estable","Estable"], ["Incremento","Estable","Estable","Estable","Estable"], ["Estable","Estable","Estable","Up","Estable"]

and so on until you complete the 3125 possibilities (5 ^ 5)

    
asked by Martin Bouhier 04.01.2018 в 23:02
source

1 answer

0

Although the answer you already have, we will pass it in clean:

from itertools import product

estados = ["Fillrate", "eCPM", "Revenue", "Impresiones", "Oportunidades"]
combinaciones = list(product(estados, repeat=len(estados)))

print(len(combinaciones))
print(combinaciones[345])
> 3125
> ('Fillrate', 'Revenue', 'Impresiones', 'Oportunidades', 'Fillrate')

We use itertools.product() to generate the combinations of the elements of estados being able in this case to repeat the 5 elements of the list repeat=len(estados) . Since product() is a generating function, if we want a list we must convert it to such by list() , keep in mind that the elements of the list are tuples, if you need another list you could do:

combinaciones = [list(e) for e in product(estados, repeat=len(estados))]
    
answered by 06.01.2018 в 01:14