title: How to iterate over a dictionary - n key-value pairs at a time
body: <p>I have a very large dictionary with thousands of elements. I need to execute a function with this dictionary as parameter. Now, instead of passing the whole dictionary in a single execution, I want to execute the function in batches - with x key-value pairs of the dictionary at a time.</p>
  
  <p>I am doing the following:</p>
  
  <pre><code>mydict = ##some large hash
  x = ##batch size
  def some_func(data):
      ##do something on data
  temp = {}
  for key,value in mydict.iteritems():
          if len(temp) != 0 and len(temp)%x == 0:
                  some_func(temp)
                  temp = {}
                  temp[key] = value
          else:
                  temp[key] = value
  if temp != {}:
          some_func(temp)
  </code></pre>
  
  <p>This looks very hackish to me. I want to know if there is an elegant/better way of doing this.</p>