I'm iterating over a list of lists in python, and I want to change the date format for some of the elements of the nested list. I tried:
for dividend in dividend_data:
for date in dividend[1], dividend[3], dividend[4], dividend[5]:
date = datetime.strptime(date, '%m/%d/%Y').strftime("%Y-%m-%d")
but the "date" variable doesn't carry back to the original list elements. I can do this by handling them individually:
dividend[1] = datetime.strptime(dividend[1], '%m/%d/%Y').strftime("%Y-%m-%d")
dividend[3] = datetime.strptime(dividend[3], '%m/%d/%Y').strftime("%Y-%m-%d")
dividend[4] = datetime.strptime(dividend[4], '%m/%d/%Y').strftime("%Y-%m-%d")
dividend[5] = datetime.strptime(dividend[5], '%m/%d/%Y').strftime("%Y-%m-%d")
But, there must be a better way to handle this, right?