I'm having a problem looping through dictionaries. I have a nested dictionary structure called dates{} like the following.
('2018-08-21 00:00:00', {'price': 10, 'height': 0.2})
('2018-08-22 00:00:00', {'price': 20, 'height': 0.3})
('2018-08-23 00:00:00', {'price': 30, 'height': 0.4})
.....
....
....
And I need to loop through each date, STARTING AT DATE 20, and calculate the average price of the past 20 days. How would I go about doing this? I tried this:
for key,value in dates.items():
n = n + 1
if n >= 20:
for key,value in dates.items():
for s in range(n-20,n):
print(value["price"])
But it won't access the price it'll create some sort of infinite loop, which means I can't work with it!
Thanks