mercredi 19 octobre 2022

Select random dictionary

Let's say I have 2 dictionaries:

pal1 = {1:"bli", 2:"bla", 3:"blub"}
pal2 = {1:"blib", 2:"blab", 3:"bleb"}

Now I want to randomly select one of the two for further usage. My thought was creating another dictionary and assign a number to each dictionary name like so:

palettes = {1:"pal1", 2:"pal2"}

now the random part:

r1 = random.randint(1,2)
used_palette = palettes[r1]

so now used_palette has the dict name I will choose for further usage as a string in it. But how do I actually access that dictionary? var = used_palette[1] won't work obviously.

Any suggestions or other ways of doing this? Thanks!




Aucun commentaire:

Enregistrer un commentaire