Today a quick video about defaultdict objects ( from the collections module).
We work through a practical example where a regular dict falls short / requires extra code you can prevent writing when using this specialized container type 💪
Chapters:
00:00 What is a defaultdict (collections module)?
00:21 Practical example
00:38 Parse the data
01:10 Using a regular dict leads to issues
02:10 Clumsy workaround
02:46 Checking if dict content is correct
03:17 Adding an assert
03:45 An alternative: dict.setdefault()
04:24 The better way: defaultdict
04:58 Recap
05:20 Using it with other factory methods (set)A
06:25 Related videos and wrap up
Docs: https://docs.python.org/3/library/col...
Practice!
Here is a promo code (valid for 1 week, till the 3rd of Aug 2023) for an intermediate Pybites exercise where you can use what you've learned in this video:
https://codechalleng.es/bites/promo/d...
This code was extracted from an existing Python tip. To get 249 more of high quality Pythonic code tips, check out our book:
http://pybit.es/tips
---
Learn more about Pybites / what we do: https://pybit.es
Get our weekly developer / mindset emails: https://pybit.es/friends/
Join our Slack community: https://pybit.es/community/
And last but not least, we appreciate any feedback to make our YouTube content better 💡
https://form.jotform.com/230941798741062 🙏
Auf dieser Seite können Sie das Online-Video Python Defaultdict Objects: Specialized Dictionaries With Initial Default Values 🐍 😍 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Pybites 27 Juli 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 240 Mal angesehen und es wurde von 13 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!