Ordering a list of dictionaries in python
Question: I've got a python list of dictionaries:

    
    
    mylist = [
    {'id':0, 'weight':10, 'factor':1, 'meta':'ABC'},
    {'id':1, 'weight':5, 'factor':1, 'meta':'ABC'},
    {'id':2, 'weight':5, 'factor':2, 'meta':'ABC'},
    {'id':3, 'weight':1, 'factor':1, 'meta':'ABC'}
    ]
    

Whats the most efficient/cleanest way to order that list by weight then factor
(numericaly). The resulting list should look like:

    
    
    mylist = [
    {'id':3, 'weight':1, 'factor':1, 'meta':'ABC'},
    {'id':1, 'weight':5, 'factor':1, 'meta':'ABC'},
    {'id':2, 'weight':5, 'factor':2, 'meta':'ABC'},
    {'id':0, 'weight':10, 'factor':1, 'meta':'ABC'},
    ]
    


Answer: 
    mylist.sort(key=lambda d: (d['weight'], d['factor']))
    

or

    
    
    import operator
    mylist.sort(key=operator.itemgetter('weight', 'factor'))
    

