title: Converting php loop to python
body: <p>I need help to convert some php code to python. The code takes the result from mongodb cursor and using loop generates an specific array. I need to produce the same array using python code.</p>
  
  <p>Here is how mongodb result looks like:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [value] =&gt; example.com
              [host] =&gt; 246.156.18.221
          )
  
      [1] =&gt; Array
          (
              [value] =&gt; example2.com
              [host] =&gt; 246.156.18.221
          )
      [2] =&gt; Array
          (
              [value] =&gt; example3.com
              [host] =&gt; 96.235.15.251
          )
  
      [3] =&gt; Array
          (
              [value] =&gt; example4.com
              [host] =&gt; 96.235.15.251
          )
  ) 
  </code></pre>
  
  <p>And here is how it looks like when I run it through the php loop:</p>
  
  <pre><code>Array
  (
      [246.156.18.221] =&gt; Array
          (
              [0] =&gt; Array
                  (
              [value] =&gt; example.com
              [host] =&gt; 246.156.18.221
                  )
  
              [1] =&gt; Array
                  (
              [value] =&gt; example2.com
              [host] =&gt; 246.156.18.221
                  )
      )
      [96.235.15.251] =&gt; Array
          (
              [0] =&gt; Array
                  (
              [value] =&gt; example3.com
              [host] =&gt; 96.235.15.251
                  )
  
              [1] =&gt; Array
                  (
              [value] =&gt; example4.com
              [host] =&gt; 96.235.15.251
                  )
      )
  )
  </code></pre>
  
  <p>This is the php code I'm using to produce the second array:</p>
  
  <pre><code>$result = array();
  foreach($mongo_data as $data){
      $result[$data['host']][] = $data;
  }
  print_r($result);
  </code></pre>
  
  <p>Now, I need to generate the same array as the second one using python code.
  Any help?</p>