title: Sub divide a dictionary into smaller parts
body: <p>I am trying to sub divide a dictionary into smaller parts. My approach works, I am just wondering if there is a more efficient way of doing it. For the sake of the example, the dictionary has 10 elements but my code can have up to 1000 and would be in batches of 50 to which I am passing to an api. </p>
  
  <p>My Questain is there a more efficient way of doing this...?</p>
  
  <pre><code>int divideamount = 2;
  
  Dictionary&lt;string, string&gt; dictionary = new Dictionary&lt;string, string&gt;();
  dictionary.Add("cat1", "cat");
  dictionary.Add("dog2", "cat");
  dictionary.Add("cat3", "cat");
  dictionary.Add("dog4", "cat");
  dictionary.Add("cat5", "cat");
  dictionary.Add("dog6", "cat");
  dictionary.Add("cat7", "cat");
  dictionary.Add("dog8", "cat");
  dictionary.Add("cat9", "cat");
  dictionary.Add("dog10", "cat");
  
  
  var divided_dictionary
      = dictionary.Select((value, index) =&gt; new { Index = index, Value = value })
                  .GroupBy(x =&gt; x.Index / divideamount)
                  .Select(g =&gt; g.Select(x =&gt; x.Value).ToDictionary(x =&gt; x.Key, x =&gt; x.Value))
                  .ToList();
  
  
  foreach (Dictionary&lt;string, string&gt; division in divided_dictionary)
  { 
      // do some work
  }
  </code></pre>
  
  <p>Thanks in advance for any help or comments.</p>