I have a list of lists that looks like this:
data = [
[u'2012-10-31', '20', 9801, '0', '0', '0', '0'],
[u'2012-10-31', '21', 9266, '0', '0', '0', '0'],
[u'2012-10-31', '22', 10526, '0', '0', '0', '0'],
[u'2012-10-31', '23', 9570, '0', '0', '0', '0'],
[u'2012-10-31', '1', 5256, '0', '0', '0', '0'],
[u'2012-10-31', '0', 5020, '0', '0', '0', '0'],
# and so on...
]
I need to sort by date first which is index 0 and hour which is index 1. How do I do that in python?
yields
Note: You could also eschew parsing the date:
suffices. Maybe that would be simpler in this particular case, but in general, you should parse dates into datetimes when you want to order them.