title: Is there a function to make user choose which operation to perform?
body: <p>I wrote code for two functions for a dictionary to be sorted either by key or by value in ascending order. I would like the user to be able to choose which sort function they want to be run by value or by key. My code for both is below.</p>
  <pre><code>d = {'b': 1, 'y': 12, 'c': 7, 'm': 2}
  sort_d = sorted(d.items())
  for i in sort_d:
      print(i[0], i[1])
  
  
  d = {'b': 1, 'y': 12, 'c': 7, 'm': 2}
  sort_d = sorted(d.items(), key=lambda x: x[1])
  for i in sort_d:
      print(i[0], i[1])
  </code></pre>