Sort python list by function September 3, 2023 by Tarik sort(my_list_of_objects, key=my_number_giving_function) same for sorted, see the Python Sorting HOWTO