Configuration

Night mode

Applications

Learn Python Essentials for Data Science Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Python Introduction Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Python, to a moderate level of essential coding proficiency.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

Have more questions?

Dictionaries

Applications

Using Dictionaries in our code

To initialize a new dictionary you would use curly braces:

dictionary = {}

Once you have created your dictionary, you can start adding key value pairs to it. The key must be a string,float,integer or tuple. The value can be any type of data structure you would like including a list or set

Below is a couple of examples of adding different types of keys and values to the dictionary.

Adding a integer key and string value

Lets imagine an example where we would like to map each letter to its placement in the alphabet. In this example, I will show how to map the first few letters.

This would print the value 1 since the keya` has a value of 1 associated with it. This can be done with any key in a dictionary, but will return an error if you try to use a key that does not exist in a dictionary.

You can check to see if a dictionary contains a specific key by using the in operator.