I have a list of stock prices in a dictionary and a list of their values. I want to go through the list to get the value of the stocks on each day but I'm having trouble resolving locations in a list when I'm using a variable to access the data.
Here's a example:
goog = [12,132,124,234,234]
msft = [432,23,234,54,23]
num_days = 5
stocks_i_own = {'goog':50, 'msft':50}
for days in range(0,num_days):
for stock in stocks_i_own:
print days, stock, stocks_i_own[stock]
print stock[days] #prints just 'g' not the value on day0
print 'vaue on ', days, ' is ', stock[days] * stocks_i_own[stock]
The problem is when I use stock[days]
to get the data. I know stock has the correct value('goog' or 'msft') and days has the correct value(range of 0-4), but when using them together I don't get the data from the list but instead the location of on the word itself. It makes sense because something like:
name = 'google'
name[0]
would return g(which its doing in my case) but is there a way for python not to see what I'm providing it as a string but instead a reference to the list?