title: Python: how does Pickle work with defaultdict
body: <p>I am new to Python and am playing with Pickle and don't understand how this works</p>
  
  <p>I define a defaultdict, write it to pickle. Then in a different script I read it and it still behaves like a defaultdict even without importing collections</p>
  
  <p>script1:</p>
  
  <pre><code>import pickle
  from collections import defaultdict
  
  x = defaultdict(list)
  
  x['a'].append(1)
  print(x)
  
  with open('pick','wb') as f:
      pickle.dump( x, f )
  </code></pre>
  
  <p>script2:</p>
  
  <pre><code>import pickle
  
  with open('pick','rb') as f:
      x = pickle.load( f )
  
  x['b'].append(2)
  print(x)
  
  y = dict()
  
  try:
      y['b'].append(2)
      print(y)
  except KeyError:
      print("Can't append to y")
  </code></pre>
  
  <p>running:</p>
  
  <pre><code>$ python3 pick2.py
  defaultdict(&lt;class 'list'&gt;, {'a': [1], 'b': [2]}) 
  Can't append to y
  </code></pre>
  
  <p>So, the 2nd script doesn't import defaultdict but the pickled x still acts like one. I'm confused :)</p>
  
  <p>How does this work in Python? Thanks for any info :)</p>