python: sort a list of lists by an item in the sublist
Question: I have a list of lists that contains users and scores as follows:

    
    
    [["user1", 100], ["user2", 234], ["user3", 131]...]
    

I want to produce a list that sorts the users by score in declining order:

    
    
    [["user2", 234], ["user3", 131], ["user1", 100]...]
    

How might I go about doing this kind of sort?


Answer: 
    >>> li = [["user1", 100], ["user2", 234], ["user3", 131]]
    >>> 
    >>> import operator
    >>> 
    >>> sorted(li, key=operator.itemgetter(1))   # Ascending order
    [['user1', 100], ['user3', 131], ['user2', 234]]
    
    >>> sorted(li, key=operator.itemgetter(1), reverse=True)  # Reverse Sort
    [['user2', 234], ['user3', 131], ['user1', 100]]
    

