From the course: Python Data Structures: Dictionaries

What is a dictionary in Python? - Python Tutorial

From the course: Python Data Structures: Dictionaries

Start my 1-month free trial

What is a dictionary in Python?

- [Instructor] Dictionaries are fundamental data type in the Python programming language. These are organized in memory, as unordered, indexed, and mutable data structures. A data structure is an implementation, that a programming language provides a programmer, to store and access data efficiently. A dictionary that we use in our daily lives, holds a word, and corresponding meaning to the word. Similarly, here a dictionary stores data in pairs. Dictionaries store a mapping of unique keys to values. A dictionary consists of a collection of key value pairs. This ability of storing bi-variate values in a dictionary is an important functionality in Python. What do I mean by bi-variate? Bi-variate implies the existence of two variable, where one variable influences the other. In case of dictionaries, the key is the independent variable, while the value is the dependent variable. But it's kind of like lists, dictionaries are much more efficient however. This makes dictionaries in Python, an excellent tool for conducting exploratory data analysis, while analyzing datasets. Each key value pair, maps the keys to its associate value. You can define a dictionary, by enclosing comma separated, list of key value pairs in curly braces. A colon separates the key from its associated value. In Python 3.6 and later, they're assorted in the order they're inserted in. Starting with Python 3.6, and officially, the part of Python specification in version 3.7, dictionaries will preserve the insertion order. Now, this code will always print the dictionary in the same way it was originally created by the programmer. Although access to the items in a dictionary does not depend on order, Python does guarantee that the order of the items in the dictionary is preserved. When displayed, items will appear in the order they were defined, and iteration through the keys will occur in that order as well. Items added to the dictionary are added at the end. If items are deleted, the order of the remaining items is retained. Dictionaries are used another programming languages as well. They are known as associative arrays, hash maps, in other languages. However, most languages lack the versatility that Python dictionaries offer. Are we ready to explore dictionaries now? The basic operations in a dictionary include, adding a key value pair, retrieving the value, corresponding to a particular key, and removing existing pairs. In the next couple of videos, we will understand the syntax of Python dictionaries by running simple programs on the command line, and also using the Sublime Editor for writing Python programs. Let's have some fun.

Contents