Selecting a random tuple from a dictionary
<p>Say I have this:</p>

<pre><code>d={'a':[(1,2),(3,4)],'b':[(9,2),(5,4)],'c':[(2,2),(7,7)]}
</code></pre>

<p>where d is a dictionary in python. I'd like to get random tuples out of this corresponding to a particular key using the <code>random.choice()</code> method.</p>

<p>This is what I'm doing and it's not working:</p>

<pre><code>random.choice(d['a'].values())
</code></pre>

<p>If you're just trying to get a random tuple out of key you pick, you've written too much:</p>

<pre><code>random.choice(d['a'])
</code></pre>

<p>(Also NB: You'll need quotes around the keys in the dictionary. Right now you're using, e.g., the undefined variable <code>a</code> instead of the string <code>'a'</code>.)</p>

python dictionary tuples