# question: how do you sort on the second element in a list of tuples >>> l = [ 'z', 'h', 'a' ] >>> sorted(l) Out[35]: ['a', 'h', 'z'] >>> lstr = [ ('z', 2), ('h', 1), ('a', 3), ('a', 4) ] >>> sorted(lstr) Out[37]: [('a', 3), ('a', 4), ('h', 1), ('z', 2)] >>> sorted(lstr, reverse=True) Out[38]: [('z', 2), ('h', 1), ('a', 4), ('a', 3)] # option 1: change the order of the tuple into the order you want it sorted >>> lnum = [ (2, 'z'), (1, 'h'), (4, 'a'), (3, 'a') ] >>> sorted(lnum, reverse=True) Out[41]: [(4, 'a'), (3, 'a'), (2, 'z'), (1, 'h')] # and then change it back to the order you want to use it >>> numl = [ (i2, i1) for (i1, i2) in lnum ] >>> numl Out[43]: [('z', 2), ('h', 1), ('a', 4), ('a', 4)] # option 2: use python function to retrieve the appropriate item when sorting >>> import operator >>> sorted(lstr, key=operator.itemgetter(1)) Out[45]: [('h', 1), ('z', 2), ('a', 3), ('a', 4)] >>> sorted(lstr, key=operator.itemgetter(1), reverse=True) Out[47]: [('a', 4), ('a', 3), ('z', 2), ('h', 1)]