title: To remove the key from dictionary in python
body: <pre><code>def length_words(new):
      a = ",.!?'"
      for a in new:
          b = new.replace(a,"")
      b = b.lower()
      b = b.split()
  
      d = []
      for i in b:
          c = len(i)
          d.append(c)
      d.sort()
      e = d[-1]
      f = d[0]
  
      new2 = {}
      for i in range(f,e+1):
          new2[i] = []
      for i in range(1,e+1):
          for j in b:
              if len(j) == i:
                  new2[i].append(j)
  
      for word in new2:
          if len(new2[word]) == 0:
              del new2[word]
      return new2
  </code></pre>
  
  <p>print(length_words("If I don’t like something, I’ll stay away from it."))</p>
  
  <p>The solution must have the dictionary : {1: ['i'], 2: ['if', 'it'], 4: ['like', 'i’ll', 'stay', 'away', 'from'], 5: ['don’t'], 9: ['something']}<br>
  I have done the program for that, but when i try to run, it displays <strong><em>"RuntimeError: dictionary changed size during iteration"</em></strong><br>
  Hpw do i delete the key with the empty list?</p>