title: Select random element from "non uniform" python dictionary
body: <p>I have a python dictionary in which values are lists of integers:</p>
  
  <pre><code>key1 -&gt; [1, 2, 3]
  key2 -&gt; [1, 2, 3, ... 17]
  key3 -&gt; [1, 2, 3, 4, 5]
  </code></pre>
  
  <p>I want to select a random tuple(key, val) where val is a random value from the list of values (for example: key2, 8). The random selection must be uniform across all the values, so for example, this method is not uniform:</p>
  
  <pre><code>random_key = random.choice(d.keys())
  random_val = random.choice(d[random_key])
  </code></pre>
  
  <p>because the lists are not of the same length.
  I know the length of the concatenation of the lists, n, so my current approach is the following:</p>
  
  <pre><code>idx = np.random.randint(n)
  c = 0
  found = False
  
  for k in D:
      for v in D[k]:
          if c == idx:
              found = True
              do_something_with_val(k, v);
              break
          c += 1
      if found:
          break
  </code></pre>
  
  <p>My question is: is there a better/faster method of doing this?</p>