i'm trying to do a 'for' loop in python, but my values keeps getting replaced. How can i write the code below in a way where i can keep a record of each iteration?
Should i be using a list[] instead of dict{} for "position"..?
for share in sharesOwned:
#how to iterate through the look up symbol?
sharesNow=lookup(share['symbol'])
position={
'name':sharesNow['name'],
'pricey': sharesNow['price'],
'symbol': sharesNow['symbol']
}
I also tried this, but it does not work..
for share in sharesOwned:
#how to iterate through the look up symbol?
sharesNow=lookup(share['symbol'])
position[share]=[
'name':sharesNow['name'],
'pricey': sharesNow['price'],
'symbol': sharesNow['symbol']
]
It returns this
TypeError: list indices must be integers, not dict
How do it put insert these information into a list i can access/call?
Original question is here but i'm really confuse, so I thought it'd solve it part by part.