Hot answers tagged

1

From the CS50 Library for Python doc for execute Returns for SELECTs, a list of dict objects, each of which represents a row in the result set; for INSERTs, the primary key of a newly inserted row (or None if none); for UPDATEs, the number of rows updated; for DELETEs, the number of rows deleted; for CREATEs, True on success; on error, a RuntimeError is ...


1

I think using a dictionary comprehension is probably easiest. I think this is the sort of thing you are trying to get? data = [{'symbol': 'ZYME', 'exchange': 'NYS', 'name': 'Zymeworks Inc.', 'date': '2019-11-06', 'type': 'cs', 'iexId': 'IEX_5253315838322D52', 'region': 'US', 'currency': 'USD', 'isEnabled': True}, {'symbol': 'ZYNE', 'exchange': 'NAS', 'name'...


1

You can use AS to rename a field, this is especially useful if you join multiple tables and return fields from several of them, or when using aggregate functions as you do here. Like "SELECT buy.stock_code AS symbol, SUM(buy.value) AS value, SUM(buy.shares) AS shares FROM buy ... Alternatively, you can drop the AS, but if I remember correctly, for some ...


1

'share' a string variable that holds the values of an item in 'sharesOwned' so it is not a dictionary. If you took the square brackets away: share = shareNow['name'] This would allow the assignment. To assign from one dictionary to another you have to initialise it as a dictionary. Once you do this then the syntax your using is correct, just remember to ...


1

In a dictionary the indices use strings, whereas lists are indexed using integers beginning with 0. The error: TypeError: list indices must be integers, not dict is because you are using string as indices instead of integers. If you want to use strings like "name" to get values from the array you should use a dictionary. Your values will get replaced for ...


Only top voted, non community-wiki answers of a minimum length are eligible