title: iterate over a subset of dictionary keys
body: <p>I am looking to learn how to pass certain keys/values in a dictionary to another function within a for loop. The "certain" keys all share the same initial string and are incremented by a trailing integer like this:</p>
  
  <pre><code>data = {}
  data["HMD1"] = [a,b,c]
  data["HMD2"] = [d,f,g] #and so on...
  </code></pre>
  
  <p>There are other keys with dissimilar names witin the same dictionary. Now within a for loop I would like to pass the values for each key that starts with "HMD" to another function. Here is a minimal working example of a failed attempt:</p>
  
  <pre><code>data = {}
  data["HMD1"] = [0,2,3]
  data["HMD2"] = [5,6,4]
  data["not"] = 1237659398
  data["HMD3"] = [1,1,1]
  
  def dummyfun(vargin):
      print(vargin)
      return vargin
  
  for f in range(1,2,1):
      out = dummyfun(data[eval(''.join(("HMD",str(f))))])
  </code></pre>
  
  <p>This was a poor guess, of course it returns an error because eval() tries to evaluate "HMD1" which is not a variable but a key in data. Does anyone know how to do this properly?</p>