I have dates in string form in list of lists in a dictionary. I wrote a function to convert date strings to datetimes. I would like to convert all string dates in my dictionary to date times. My code only converts the first sublist in each table and it has no way of getting the others. What's the best way to do this?
import datetime
def parse_date(datestamp):
try:
return datetime.datetime.strptime(str(datestamp)[:10], '%Y-%m-%d')
except ValueError:
pass
My_Dict = {
'Value1': {'Dates' : [['2014-10-14', 10, '2014-10-13', '2014-11-03'], ['2014-10-14', '2014-10-14', '2014-11-03']]},
'Value2': {'Dates' : [['2014-10-14', '2014-10-13', '2014-11-03'], ['2014-10-14', '2014-10-14', '2014-11-03']]},
}
for tbl in My_Dict:
print [parse_date(x) for x in My_Dict[tbl]['Dates'][0]]