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
Post a Comment