I want take random key in this dict :
{'F' : 'FF', 'B' : 'F[[-B][+B]]F[+FB]-B','B': 'F[-B]F[-FB]+B',}
I have same key this is normal and if the key is ‘B’ I want one of the two associated values to be returned to me.
i.e. if the key is ‘B’ the result must be'F[[-B][+B]]F[+FB]-B'or'F[-B]F[-FB]+B'randomly
and i didn’t see how to make that.
>Solution :
A dictionary can only have unique keys.
You could use a dictionary of lists and get a random choice using random.choice:
d = {'F' : ['FF'], 'B': ['F[[-B][+B]]F[+FB]-B', 'F[-B]F[-FB]+B']}
import random
random.choice(d['B'])
output: 'F[[-B][+B]]F[+FB]-B' or 'F[-B]F[-FB]+B' (50% chance each)