How to make a function loop through multiple dictionaries in Python
<p>I am looking to create a function in Python that will move between multiple dictionaries that are within a class. There will be several dictionaries that the user will go through in order, and I want the function to be able to go through each one and select a random pair from the dictionary. The user will then submit an answer or some input, and then the function will move on to the next dictionary, again selecting a random pair.</p>

<p>Short of creating a separate function for each dictionary, Iâm not sure how to do this. Any help would be appreciated.</p>

<p>Well, if you've got a list of dictionaries in the class, something like:</p>

<pre><code>import random
for d in dict_list:
    random_pair = random.choice(d.items())
    # Then do whatever you were going to do with that pair
    # then it goes on to the next dictionary in the list
</code></pre>

<p>If you don't already have all the dictionaries in a list, just make the list before that loop.</p>

python dictionary