title: Why the dict.setdefault method in Python does not work as expected?
body: <p><strong>from docs:</strong><br>
  <em>setdefault(key[, default])<br>
  If key is in the dictionary, return its value. If not, insert key with a value of default and return default. default defaults to None.</em><br>
  <a href="https://docs.python.org/3/library/stdtypes.html#mapping-types-dict" rel="nofollow noreferrer">https://docs.python.org/3/library/stdtypes.html#mapping-types-dict</a>  </p>
  
  <p>code:  </p>
  
  <pre><code>def f():
      print('func work')
      return 33
  d = {}
  key = 'key'
  print(d.setdefault(key,f()), '  - key not in dict')
  print(d.setdefault(key,f()), '  - key in dict, but method "setdefault" not      return value, instead it run func again')
  </code></pre>
  
  <p>result:  </p>
  
  <blockquote>
    <p>> Python 3.6.1 (default, Dec 2015, 13:05:11)
    [GCC 4.8.2] on linux<br>
    > func work<br>
    > 33   - key not in dict<br>
    > func work<br>
    > 33   - key in dict, but method "setdefault" not return value, instead it run func again  </p>
  </blockquote>
  
  <p>Why?</p>