title: Is there an accepted way to have a function pop a value from a parameter?
body: <p>Essentially, I would like to know if I should be attempting to avoid side effects in functions if possible, or if side effects are acceptable in certain situations.  I would like to have a function which <code>pop</code>s and returns a key from a dictionary and am curious if the function should return just the key:</p>
  
  <pre><code>def popkey(d):
      k, v = d.popitem()
      return k
  
  mykey = popkey(d)
  </code></pre>
  
  <p>or if it should also return the modified dictionary:</p>
  
  <pre><code>def popkey(d):
      k, v = d.popitem()
      return k, d
  
  mykey, d = popkey(d)
  </code></pre>
  
  <p>More specifically, I have something like the following, where I need keep looking through the dictionary, so I wanted to <code>pop</code> the keys as they are paired with the elements from a list.</p>
  
  <pre><code>def pop_nearest(d, pt):
      """Pops the key in `d` which is nearest to pt."""
      to_pop = min(d.iterkeys(), key=lambda a: abs(a - pt))
      d.pop(to_pop)
  
  pts = [1,3,5,7,9]
  for pt in pts:
      nearest_pt = pop_nearest(d, pt)
      # do some other stuff
  </code></pre>