title: how to create a dictionary with list of dictionaries as values from a list of dictionaries
body: <p>I have this sample list of dictionaries:</p>
  <pre><code>[
    {
      &quot;name&quot;: &quot;like father&quot;, 
      &quot;director&quot;: &quot;Ajun kun&quot;, 
      &quot;edited&quot;: &quot;2014-12-20T21:23:49.867000Z&quot;, 
      &quot;similar_movies&quot;: [
        &quot;http://movies.dev/api/films/1/&quot;, 
        &quot;http://movies.dev/api/films/3/&quot;, 
     
      ], 
      &quot;rating&quot;: &quot;2.0&quot;, 
  
    }, 
    {
      &quot;name&quot;: &quot;be like her&quot;, 
      &quot;director&quot;: tuned ku&quot;, 
      &quot;edited&quot;: &quot;2014-12-20T21:23:49.870000Z&quot;, 
      &quot;similar_movies&quot;: [
        &quot;http://movies.dev/api/films/1/&quot;
      ]
    }, .......
  ]
  </code></pre>
  <p>Some of the dictionaries in the list contain ratings while others do not. I want to generate a new dictionary of like the dictionary below sorted by the ratings:</p>
  <pre><code>    {
          &quot;movies&quot;:[
              {&quot;name&quot;: &quot;movie_4&quot;, &quot;rating&quot; : 0.1},
              {&quot;name&quot;: &quot;movie_1&quot;, &quot;rating&quot; : 0.3},
              {&quot;name&quot;: &quot;movies_5&quot;, &quot;rating&quot; : 0.5}
          ],
          &quot;movies_without_rating&quot;: [
              {&quot;name&quot;: &quot;movie_8&quot;},
              {&quot;name&quot;: &quot;movie_3&quot;} 
          ]
      }
  
  </code></pre>
  <p>Here is my sample code:</p>
  <pre><code>from flask import Flask,  jsonify, request
  import requests
  from collections import ChainMap
  
  app = Flask(__name__)
  
  @app.route('/movies', methods=['GET'])
  def returnAll():
       #note: the URL is just a demo url
      response = requests.get(&quot;https://movies.dev/api/movies/&quot;)
  
      results = response.json()['results']
  
      general_dic = {}
  
  
    
      for result in result:
          for key, val in result:
              if (key == 'rating'):
                  general_dic['movies'] 
               else:
                   general_dic['movies_with_rating']
      
      return general_dic
  
      
      return jsonify(results)
  
  
  
  
  
  if __name__ == &quot;__main__&quot;:
      app.run(debug=True)
  </code></pre>
  <p>I got stuck and I couldn't continue, I will greatly appreciate your help.</p>