title: Why does RuntimeError: dictionary changed size during iteration occour?
body: <p>During practicing leetcode some <code>RuntimeError: dictionary changed size during iteration</code> occurs that I don't understand why since I don't mutate the dict.</p>
  <pre class="lang-py prettyprint-override"><code>import collections
  from typing import List
  import sys
  
  class Solution:
      def findRedundantConnection(self, edges: List[List[int]]) -&gt; List[int]:
          graph = collections.defaultdict(set)
          for v1, v2 in edges:
              graph[v1].add(v2)
  
          def dfs(v, v_prev):
              for v1 in graph[v]:
                  if dfs(v1, v):
                      break
  
          for v in graph:  #  RuntimeError: dictionary changed size during iteration
              dfs(v, None)
              print(sys.getsizeof(graph)) # shows the same size
  
  
  edges = [[1, 2], [1, 3], [2, 3]]
  output = [2, 3]
  result = Solution().findRedundantConnection(edges)
  assert output == result
  </code></pre>
  <p>It's an anomalia since this snippet works:</p>
  <pre class="lang-py prettyprint-override"><code>d = {1: {1}, 2: {2}, 3: {3}}
  
  for v in d.keys():
      for v1 in d:
          print(v, v1)
  </code></pre>