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

python - Setting ctypes.Structure default values -

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

java - HTTP Status 500 - No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode -