I have the following dictionary:
And to get each possible permutation without repetition in a specific order (i.e. cartesian products) I use the following code:
How can I make the above program saves each iteration to a dataframe such as it throws an output like this one:
1 2 3 4 5 6 |
the_dictionary_list = { 'Fondo' : [ 'Oceano.png' ], 'Cuerpo' : [ 'Cuerpo_cangrejo.png' ], 'Ojos' : [ 'Antenas.png' , 'Pico.png' , 'Verticales.png' ], 'Color' : [ 'Amarillo.png' , 'Blanco.png' , 'Rojirosado.png' , 'Turquesa.png' , 'Verde_oscuro.png' , 'Zapote.png' ], 'Pinzas' : [ 'None' , 'Pinzitas.png' , 'Pinzotas.png' , 'Pinzota_pinzita.png' ], 'Puas' : [ 'None' , 'Arena.png' , 'Marron.png' , 'Purpura.png' , 'Verde.png' ]} |
1 2 3 4 5 |
import itertools as it AllKeysNames = [ 'Fondo' , 'Cuerpo' , 'Ojos' , 'Color' , 'Pinzas' , 'Puas' ] Combinations = list (it.product( * (the_dictionary_list[Name] for Name in AllKeysNames))) print ( f '{Combinations}' ) |
Output:Index | Permutations | FilePermutations
0 |Fondo+Cuerpo+Ojos+Color+Pinzas+Puas|Oceano.png+Cuerpo_cangrejo.png+Antenas.png+Amarillo.png+None+None
1 |Fondo+Cuerpo+Ojos+Color+Pinzas+Puas|Oceano.png+Cuerpo_cangrejo.png+Antenas.png+Amarillo.png+None+Arena.png
2 |Fondo+Cuerpo+Ojos+Color+Pinzas+Puas|Oceano.png+Cuerpo_cangrejo.png+Antenas.png+Amarillo.png+None+Marron.png
.
.
.
The information within the Permutations
column will remain constant, and the dataframe would ended up with an index length of 359
.