Feb-19-2020, 09:42 PM
Hi, I've created some terribly slow code and I'd like to learn how I can improve it.
I want to turn the ownedcards dictionary of card id's and quantities into a list of card names and quantities.
any advice would be appreciated
I want to turn the ownedcards dictionary of card id's and quantities into a list of card names and quantities.
ownedcards = {16: 2, 20: 139}
card_sections = [{'card_id': '16',
'card_set': '1000',
'fully_upgraded': '',
'fusion_level': '0',
'level': '1',
'name': 'Terminator-1',
'rarity': '2',
'sp_value': '5'},
{'card_id': '20',
'card_set': '1000',
'fully_upgraded': '',
'fusion_level': '',
'level': '3',
'name': 'Benediction-3',
'rarity': '4',
'sp_value': '60'}]
card_names = []
for (card_id, qty) in ownedcards.items():
for key in card_sections:
if card_id == key['card_id']:
card_names.append(key['name'] + ' #' + str(qty))
card_names outputs:
['Terminator-1 #2',
'Benediction-3 #139']card_sections is a list of 46750 dicts and the ownedcards dict can be 1000+ elements long so the above solution is really slow. any advice would be appreciated
