My SQL table 'portfolio' has three fields: id, stock, shares. I use the below code to retrieve stock and shares for a particular user. In my test case, user has three different stocks(TEXT), with corresponding shares(INTEGER). When I print out holdings I get:

holdings = [{'shares': 'ab'}, {'shares': 'ba'}, {'shares': 'nvda'}]

Why is the shares key paired with the stock value? What happens to the stock key and the shares values?

# query portfolio for stock holdings
holdings = db.execute("SELECT stock shares FROM portfolio WHERE id = :id", id=session['user_id'])

1 Answer 1


Just found that by placing a comma between stock and shares I get holdings = [{'shares': 2, 'stock': 'ab'}, {'shares': 1, 'stock': 'ba'}, {'shares': 3, 'stock': 'nvda'}]


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .