Hi I'm trying to become a better programmer with short and clean code. I'm trying to loop through a list in a list and change it to dictionary inside a list here is my code right now please show me if there is anyway to achieve is with shorter lines of code.
1st I need to loop through the list to change the miliseconds to date and then I need to loop through and add keys to the list so that I know what each value is.
import datetime
formatter = ['Date', 'Open', 'Close', 'High', 'Low', 'Volume']
list = [[1364770800000, 93.2, 93.033, 93.29, 92.9, 116.0018], [1364774400000, 93.25, 93.1, 100, 93.03, 345.58388931]]
print(list)
def mili_to_date(d):
d /= 1000.0
return datetime.date.fromtimestamp(d).strftime('%Y-%m-%d')
for i, row in enumerate(list):
for index, column in enumerate(row):
if index == 0:
list[i][0] = mili_to_date(column)
else:
pass
for i, row in enumerate(list):
list[i] = {}
for index, column in enumerate(row):
list[i][candles_formatter[index]] = column
print(list)