Ordering a list of dictionaries in python
mylist.sort(key=lambda d: (d['weight'], d['factor']))
or
import operator
mylist.sort(key=operator.itemgetter('weight', 'factor'))
mylist.sort(key=lambda d: (d['weight'], d['factor']))
or
import operator
mylist.sort(key=operator.itemgetter('weight', 'factor'))