Dictionaries in python!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

codinglearners1974 8 views 9 slides Aug 31, 2025
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

good


Slide Content

Dictionaries
Topics:
▪Understanding Dictionaries
▪Associated Methods

Dictionary
Dictionaries
Dictionaryin Python is an unordered collection of
data values, used to store data values like a map,
which unlike other Data Types that hold only single
value as an element, Dictionary
holdskey:valuepair. Key value is provided in the
dictionary to make it more optimized.
Creating Dictionaries
In Python, a Dictionary can be created by placing
sequence of elements within curly{}braces,
separated by ‘comma’

Examples
>>> s =
{"name":"vamsi","city":"Hyderabad","gender":"male"}
>>> print(s)
{'name': 'vamsi', 'city': 'Hyderabad', 'gender': 'male'}
>>> print(type(s))
<class 'dict'>

Dictionary Methods
Dictionary Object is defined with the following pre-defined
Methods
.clear(...)
Remove all elements from this Dictionary.
.copy()
It creates a shallow copy of the Dictionary object
.get()
It is a conventional method to access a value for a key.

Dictionary Methods
.items()
Returns a list of dict’s (key, value) tuple pairs.
.keys()
Returns list of dictionary dict’s keys
.values()
Returns list of dictionary dict’s values.

Dictionary Methods
.pop()
Removes and returns an element from a dictionary having the
given key.
.popitem()
Removes the arbitrary key-value pair from the dictionary and
returns it as tuple.

Dictionary
Examples
>>> x = {"name":"vamsi","city":"hyderbad","gender":"male"}
>>> print(x)
{'name': 'vamsi', 'city': 'hyderbad', 'gender': 'male'}
>>> x.keys()
dict_keys(['name', 'city', 'gender'])
>>> x.values()
dict_values(['vamsi', 'hyderbad', 'male'])
>>> x.items()
dict_items([('name', 'vamsi'), ('city', 'hyderbad'), ('gender', 'male')])

Dictionary
Examples
>>> x.get("name")
'vamsi'
>>> x["city"]
'hyderbad'
>>> x.pop("gender")
'male'
>>> print(x)
{'name': 'vamsi', 'city': 'hyderbad'}
>>> x.popitem()
('city', 'hyderbad')
>>> print(x)
{'name': 'vamsi'}

Dictionary
Examples
>>> print(x)
{'name': 'vamsi'}
>>> x["country"]="India"
>>> print(x)
{'name': 'vamsi', 'country': 'India'}
>>> x.clear()
>>> print(x)
{}
Tags