title: Iteration of nested dictionary to find similar values and then add to a list of dictionary with a same key
body: <p>CSV file is taken into networkx graph and iterated to the below format.
  Here is the code which I am using to iterate through the dictionary.</p>
  <pre><code>
  diction = {
    &quot;1234&quot;:{
            &quot;name&quot;:&quot;XYZ&quot;,
            &quot;rollNo&quot;:&quot;2&quot;,
            &quot;marks&quot;:&quot;40&quot;
     },
    &quot;2122&quot;:{
            &quot;name&quot;:&quot;XYZ&quot;,
            &quot;rollNo&quot;:&quot;2&quot;,
            &quot;marks&quot;:&quot;60&quot;
     }
  }
  new_dict = {}
  key_list = []
  for key,values in diction.items():
      if key not in key_list:
  
          name = values['name']
          rollNo = values['rollNo']
          for k,v in diction.items():
              if k not in key_list:
                  key_list.append(key)
                  key_list.append(k)
                  if name == v['name'] and rollNo == v['rollNo']:
                      if (k,key) not in key_list:
                          new_dict.setdefault(key, []).append(v)
                      elif key in key_list:
                          new_dict[key].append(v)
                      elif k in key_list:
                          new_dict[k].append(v)
                  else:
                      new_dict.setdefault(key, []).append(v)
  
  print(new_dict)
  </code></pre>
  <p>Input:</p>
  <pre><code>{
    &quot;1234&quot;:{ 
            &quot;name&quot;:&quot;XYZ&quot;,
            &quot;rollNo&quot;:&quot;2&quot;,
            &quot;marks&quot;:&quot;40&quot;
     },
    &quot;2122&quot;:{
            &quot;name&quot;:&quot;XYZ&quot;,
            &quot;rollNo&quot;:&quot;2&quot;,
            &quot;marks&quot;:&quot;60&quot;
     }
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>{
    &quot;1234&quot;:[{ 
            &quot;name&quot;:&quot;XYZ&quot;,
            &quot;rollNo&quot;:&quot;2&quot;,
            &quot;marks&quot;:&quot;40&quot;
         },
         {
            &quot;name&quot;:&quot;XYZ&quot;,
            &quot;rollNo&quot;:&quot;2&quot;,
            &quot;marks&quot;:&quot;60&quot;
        }]
  }
  </code></pre>
  <p>I have such 5M keys to be checked.
  I am currently using for within for which is taking hell lot of time, as the time complexity is n^n.
  Want an optimized solution.</p>