Dictionaries
In this lecture, you'll learn everything about Python dictionaries; how they are created, accessing, adding, removing elements from them and various built-in methods.
Creating Python Dictionary
# empty dictionary
my_dict = {}
# dictionary with integer keys
my_dict = {1: 'apple', 2: 'ball'}
# dictionary with mixed keys
my_dict = {'name': 'John', 1: [2, 4, 3]}
# using dict()
my_dict = dict({1:'apple', 2:'ball'})
# from sequence having each item as a pair
my_dict = dict([(1,'apple'), (2,'ball')])Accessing Elements from Dictionary
Changing and Adding Dictionary elements
Removing elements from Dictionary
Python Dictionary Methods
Method
Description
Python Dictionary Comprehension
Other Dictionary Operations
Dictionary Built-in Functions
Function
Description
Last updated