r/badcode • • Jul 14 '21

python Try/Except in Python - Sigh

Post image
662 Upvotes

93 comments sorted by

View all comments

Show parent comment

1

u/AchillesDev Jul 14 '21 edited Jul 14 '21

jsonResponse is a dict, you just pass that in to the defaultdict constructor with your logic for handling missing keys. Alternatively, you could loop through the Items array and build defaultdicts for each Item dictionary