Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/17-Advanced Python Objects and Data Structures/04-Advanced Dictionaries.ipynb
Views: 648
Advanced Dictionaries
Unlike some of the other Data Structures we've worked with, most of the really useful methods available to us in Dictionaries have already been explored throughout this course. Here we will touch on just a few more for good measure:
Dictionary Comprehensions
Just like List Comprehensions, Dictionary Data Types also support their own version of comprehension for quick creation. It is not as commonly used as List Comprehensions, but the syntax is:
One of the reasons it is not as common is the difficulty in structuring key names that are not based off the values.
Iteration over keys, values, and items
Dictionaries can be iterated over using the keys(), values() and items() methods. For example:
Viewing keys, values and items
By themselves the keys(), values() and items() methods return a dictionary view object. This is not a separate list of items. Instead, the view is always tied to the original dictionary.
Great! You should now feel very comfortable using the variety of methods available to you in Dictionaries!