Shi Mu wrote: > I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list > based on the second value in the item? > That is, > I want the list to be: > [[3,2],[1,4],[2,5],[3,9]]
>>> lst = [[1,4],[3,9],[2,5],[3,2]] >>> lst [[1, 4], [3, 9], [2, 5], [3, 2]] >>> >>> >>> lst.sort(cmp = lambda x,y: cmp(x[1], y[1])) >>> lst [[3, 2], [1, 4], [2, 5], [3, 9]] >>> works for Python 2.4 in earlier Pythons just let cmp = .. away Regards, Daniel -- http://mail.python.org/mailman/listinfo/python-list