我有以下代码来查询股票购买数据库:
dicts = db.execute("SELECT symbol, SUM(balance) FROM portfolio")
这输出:
[{'symbol': 'F', 'SUM(balance)': 59.55}, {'symbol': 'MSI', 'SUM(balance)': 1374.1999999999998}]
和我创建的用于将 SUM(balance) 数字转换为货币的列表(称为“总计”)
for item in db.execute("SELECT SUM(balance) FROM portfolio GROUP BY symbol"): total.append(usd(item["SUM(balance)"]))
哪些输出:
['$59.55', '$1,374.20']
如何将 total[] 中的项目添加到字典中,以便它输出:
[{'symbol': 'F', 'SUM(balance)': 59.55, 'total': $59.55}, {'symbol': 'MSI', 'SUM(balance)': 1374.1999999999998, 'total': $1,374.20}]
我最终想在包含总值的字典上运行 for 循环
收到一只叮咚
相关分类