Light Mode
Dark Mode
Difference between s and data[s]

So here is the code:

def best_stock(data):

maxprice = 0 answer = "" for s in data: print(data[s]) if data[s] > maxprice: max_price = data[s] answer = s return answer

so… if you print(data[s])

you get the integer assigned to the string

but if you print(s)

you get the string

so why is this? s is the bit of the array that is currently being looked at by the program, right? So why is it printing the string if you just ask for s and the integer if you ask for data[s]?

Created: Sept. 30, 2019, 8:26 p.m.
Updated: Oct. 1, 2019, 6:50 p.m.
0
8
User avatar
rebgrasshopper