From the course: Python Data Analysis

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Dictionaries and sets

Dictionaries and sets - Python Tutorial

From the course: Python Data Analysis

Start my 1-month free trial

Dictionaries and sets

- [Instructor] While lists give us a way to retrieve values by their index. Python dictionary or dicts associate keys with values. After my imports, let me write a simple dictionary. Dicts are written with curly braces, separating items with commas and prefixing them by their key in a column. For instance, the capitals of a few countries. Just as we do with lists, values are accessed with a bracket notation. But instead of a number, we're going to use a key. For instance, we may wish to look at the capital of Italy. The same notation can be used to add items to a dictionary. Accessing a nonexistent item results in a key error. We can also check whether an item exists or not with the in operator. So we have Italy, but not Germany. Combining two dictionaries requires a little more thought than combining two lists. Unlike lists, we cannot just use the plus to add them. That's because we need to specify what happens…

Contents