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

c++ - list<myClass<int> * > sort -

c - Defining floating point constants, how many digits are useful? -

C# Apple Bonjour - how to monitor service records within Windows -