title: Dictionary performance for search and remove items
body: <p>I have a problem with Python dictionary performance.</p>
  
  <p>I have to read a file that with many x,y location and if draw this point it
  looks like a circle , and i have to resize this circle by a specific number from
  the edge. If Mydict has over 50000 items, it becomes slow.</p>
  
  <p>Mydict is like  <code>{ (X,Y) : {value:1 ,value:2} ,}</code><br>
  Key is a tuple and value is another dict.</p>
  
  <pre><code>Mydict = get_data()
  cut_num = 5 # cut size
  # start remove x
  max_group = tuple(map(max,*Mydict))
  min_group = tuple(map(min,*Mydict))
  X_max = max_group[0] - cut_num
  X_min = min_group[0] + cut_num
  
  remove_keys =[k for k in Mydict if k[0]&gt; X_max or k[0]&lt; X_min ]
  for key in remove_keys:
      del Mydict[key]
  </code></pre>
  
  <p>Remove X value is faster just about 1 second.</p>
  
  <p>But I don't know how to remove Y value  in a efficiency way.</p>
  
  <p>I write a function to get Y Max,Min By X value:</p>
  
  <pre><code>def Get_Y_By_Xaxis(Mydict,X_value):
      temp_dict = {k for k in Mydict if k[0] == X_value }
      max_group = tuple(map(max,*temp_dict ))
      min_group = tuple(map(min,*temp_dict ))
      return (min_group[1],max_group[1])
  </code></pre>
  
  <p>And start to remove Y value. I do it like this</p>
  
  <pre><code>for i in range(X_min ,X_max+1 ):
      limits = Get_Y_By_Xaxis(Mydict , i)
      remove_keys =[k for k in Mydict
                    if (k[0] == i and k[1] &gt; limits[0] - cut_num  )
                    or (k[0] == i and k[1] &lt; limits[1] + cut_num  )]
      for key in remove_keys:
          del Mydict[key]
  </code></pre>
  
  <p>The will cost about 60~70 second for a dictionary with 150000 item</p>
  
  <p>Is this code will become faster or do I have to use some package to help me?</p>