Apr-20-2019, 08:52 PM
Dear Python Developers,
I hope you are having a great saturday. Could you please assert me if I'm coding this correct:
The goal is to convert my list into a library:
1) The code works but it provides me the same key for all items in the list. I'm I doing this right?
I hope you are having a great saturday. Could you please assert me if I'm coding this correct:
The goal is to convert my list into a library:
1) The code works but it provides me the same key for all items in the list. I'm I doing this right?
#Add list of stocks to dictionary x = [("GOOGL", 125, 772.88, 941.53), ("MSFT", 85, 56.60, 73.04), ("RDS-A", 400, 49.58, 55.74), ("AIG", 235, 54.21, 65.27), ("FB", 150, 124.31, 172.45)] mydata = {} for i in range(len(x)): mydata[x[i]] = x.count(x[i]) print (mydata)
Output:{('GOOGL', 125, 772.88, 941.53): 1, ('MSFT', 85, 56.6, 73.04): 1, ('RDS-A', 400, 49.58, 55.74): 1, ('AIG', 235, 54.21, 65.27): 1, ('FB', 150, 124.31, 172.45): 1}