Mike Driscoll
Mike Driscoll

@driscollis

4 Tweets Jan 28, 2023
Let's talk about "unpacking" lists, tuples, and more with #Python!
The first unpacking example I want to show is how you can use a single asterisk to unpack all these different types!
🐍🔥
You can also use the double-asterisk to unpack dictionaries.
In this example, you unpack a nested dictionary into another dictionary. Note that both dictionaries have the same key.
Since this is executed from left-to-right, you unpack and then overwrite the "x" key with 1
Here's a more complicated example of dictionary unpacking.
You may need to re-read this a few times to fully understand what is going on here.
I have a short article on unpacking generalizations in #Python on @mousevspython
blog.pythonlibrary.org

Loading suggestions...