title: Sort python list by function
body: <p>I have a function that takes an object as an argument and gives me a number. I wish to use this number as the key to sort my list.</p>
  
  <p>If I were to iterate over the list I would do something like:</p>
  
  <pre><code>sorted_list = []
  for object in my_list_of_objects:
      i = my_number_giving_function(object)
      sorted_list.insert(i, object)
  </code></pre>
  
  <p>How can I user <code>sorted</code> to get the same result, and is it advisable? This is what I came up with but I don't know what to put in the '???'</p>
  
  <pre><code>sorted_list = sorted(my_list_of_objects, key=my_number_giving_function(???))
  </code></pre>