To choose a random key from a dictionary named my_dict
, you can use:
random.choice(list(my_dict))
This will work in both Python 2 and Python 3.
For more information on this approach, see: https://stackoverflow.com/a/18552025
To choose a random key from a dictionary named my_dict
, you can use:
random.choice(list(my_dict))
This will work in both Python 2 and Python 3.
For more information on this approach, see: https://stackoverflow.com/a/18552025