title: Python nested dictionary iterate and create new dictionary
body: <p>I have a python dictionary where I am iterating it and creating a new dictionary with some calculations. My current code is working fine but I want to know what are the other different ways to do it?</p>
  <p>The logic is-</p>
  <pre><code>1. if the same `room` has multiple `rate` codes then append it to that room.
  2. get the lowest price for every room type.
  </code></pre>
  <p><strong>Existing Code:</strong></p>
  <pre><code>datas = [
      {&quot;code&quot;: &quot;A1KXDY&quot;, &quot;room&quot;: &quot;A1K&quot;, &quot;rate&quot;: &quot;XDX&quot;, &quot;price&quot;: 10},
      {&quot;code&quot;: &quot;B1KXDY&quot;, &quot;room&quot;: &quot;B1K&quot;, &quot;rate&quot;: &quot;XDX&quot;, &quot;price&quot;: 20},
      {&quot;code&quot;: &quot;C1KXDY&quot;, &quot;room&quot;: &quot;C1K&quot;, &quot;rate&quot;: &quot;XDX&quot;, &quot;price&quot;: 30},
      {&quot;code&quot;: &quot;A1KXDY&quot;, &quot;room&quot;: &quot;A1K&quot;, &quot;rate&quot;: &quot;XDY&quot;, &quot;price&quot;: 5},
      {&quot;code&quot;: &quot;B1KXDY&quot;, &quot;room&quot;: &quot;B1K&quot;, &quot;rate&quot;: &quot;XDY&quot;, &quot;price&quot;: 10},
      {&quot;code&quot;: &quot;C1KXDY&quot;, &quot;room&quot;: &quot;C1K&quot;, &quot;rate&quot;: &quot;XDY&quot;, &quot;price&quot;: 40},
  ]
  final_result = {}
  for data in datas:
      display_rate = data[&quot;price&quot;]
      if data[&quot;room&quot;] in final_result:
          existing_room = final_result[data[&quot;room&quot;]]
          existing_room[&quot;rate_codes&quot;].append(data[&quot;rate&quot;])
          current_rate = existing_room[&quot;display_rate&quot;]
          if current_rate &gt; display_rate:
              existing_room[&quot;display_rate&quot;] = display_rate
          continue
  
      room_data = {&quot;display_rate&quot;: display_rate, &quot;rate_codes&quot;: [data[&quot;rate&quot;]]}
  
      final_result[data[&quot;room&quot;]] = room_data
  print(final_result)
  </code></pre>
  <p><strong>Expected Output:</strong></p>
  <pre><code>{'A1K': {'display_rate': 5, 'rate_codes': ['XDX', 'XDY']}, 'B1K': {'display_rate': 10, 'rate_codes': ['XDX', 'XDY']}, 'C1K': {'display_rate': 30, 'rate_codes': ['XDX', 'XDY']}}
  </code></pre>