I have a list of tuples, each containing a date, and then a number.
days = [('04/02/15', 4.5),('03/15/15', 5.0),('04/21/15', 1.9)]
I want to sort them by date. How do I go about converting them into DateTime objects or otherwise sorting them?
I have a list of tuples, each containing a date, and then a number.
days = [('04/02/15', 4.5),('03/15/15', 5.0),('04/21/15', 1.9)]
I want to sort them by date. How do I go about converting them into DateTime objects or otherwise sorting them?
You could use strptime
:
from time import strptime
days = [('04/02/15', 4.5), ('03/15/15', 5.0), ('04/21/15', 1.9)]
days.sort(key = lambda tup: strptime(tup[0], '%m/%d/%y'))