sorting - python sort objects by difference in attributes/weights -


is there way sort function in python?

the array holds objects each 1 has weight value.

i'd appreciate javascript sort.

i tried doing cmp run error:

typeerror: comparison function must return int, not float

use python's built in sorted function lambda, , cast result integer.

sorted_list = sorted(unsorted_iterable, lambda x, y: int(x.weight - y.weight))


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -