The 6 AI Engineering Patterns, come build with Greg live:Β Starts Jan 6th, 2025
Leverage
Glossary

Dictionary

Python dictionary data type and key-value pairs

Python Dictionary (or dict) is a type of data. Just like a string, int, float, list, etc. You can have a datatype called dictionary. Its key characteristic is the well-known key:value pair layout.

Think of these as mini vlookups in Excel. The key refers to the item that you want to find, the value refers to the data related to the key. These are extremely helpful when you want to have a map that will return your information.

The keys in a dictionary must be unique. Values do not have to be unique. Keys and values are separated by a colon : .

my_dict = {
    'key1' : 'value1',
     key2  :  value2,
    'key3' : 'value3',
}

A dictionary is a type of mapper in python. That means you put something in, and something comes out.

ou can get creative with the data types you have as keys and values. Python can handle ints, strings and floats. Dictionary keys can not be lists.

Let’s take a look at a python dictionary code sample.

Link to code above

On this page

No Headings