Dictionaries play an absolutely central role in Python. In fact, the previous two tips both touched on dictionaries in one way or another.
This tip is about merging dictionaries.
Let's imagine we are writing a web application in Python. You'll see that your action methods will receive data from several locations. Consider a web form at the URL server.com/customer/edit/271/Fast&20apps?id=1&render_fast=True.
In there is a form with the data email = j@j.com and name = Jeff.
This data may appear in three dictionaries. One for the route, one for the query string, and one for the form data. As the web developer, answer the question where do I get the ID (which dictionary)? What if it's missing from one, where do I fall back to? This is not clean code.
We can fix it by merging the dictionaries into a master "submitted data" dictionary with the right priorities.
How do we do this merge? This video and related blog post will show you the options.
On this page of the site you can watch the video online Pythonic code: Tip #3 Merging dictionaries cleanly in Python with a duration of hours minute second in good quality, which was uploaded by the user Michael Kennedy 05 August 2016, share the link with friends and acquaintances, this video has already been watched 9,926 times on youtube and it was liked by 139 viewers. Enjoy your viewing!