I have been struggling with this problem set (pset7) for a couple weeks now and I have looked at countless resources while trying to get my code working. I am the point where I do not remember what is happening in my code at all. Could someone please explain what is actually getting stored in ledger? I know that the db.execute returns a list of some sort but how are the two fields (company and total_shares) related to each other now? Also, in the for loop, what is actually being iterated through and being stored where? I felt like had a pretty good grasp of these concepts before this pset but now I don't understand.
P.S. Please ignore the magic number, it is a placeholder for now.
def index(): """Show portfolio of stocks""" current_cash_list = db.execute("SELECT cash FROM users WHERE id = :user_id", user_id=session["user_id"]) cash = float(current_cash_list["cash"]) total = 8 ledger = db.execute("SELECT company, SUM(number_purchased) AS total_shares FROM ledger WHERE user_id = :user_id GROUP BY company ORDER BY company", user_id=session["user_id"]) for company in ledger: company = company["company"] total_shares = company["total_shares"] price_per_share = lookup(company) total_value = total_shares * price_per_share if request.method == "POST": return render_template("index.html", ledger=ledger, cash=cash, total=total, price_per_share=price_per_share) else: return render_template("index.html", ledger=ledger, cash=cash, total=total)