I start out with date strings:
from operator import itemgetter
import datetime as DT
# unsorted dates
raw = (map(int, "2010-08-01".split("-")),
map(int, "2010-03-25".split("-")),
map(int, "2010-07-01".split("-")))
transactions = []
for year, month, day in raw:
new = (DT.date(year, month, day), "Some data here")
transactions.append(new)
# transactions is now a list with tuples nested inside, for example
# [(date, "Some data here"), (date, "Some data here")]
sorted(transactions, key=itemgetter(0))
for info in transactions:
print info
I get the following, and its not sorted according to date:
(datetime.date(2010, 8, 1), 'Some data here')
(datetime.date(2010, 3, 25), 'Some data here')
(datetime.date(2010, 7, 1), 'Some data here')
How do I sort these according to date?