Dictionary
1D Adietionary is an unordered collection of tems.
[L Each tem ofa dietonary has a key and corresponding value
associated tot (key: value.
1D keys must be immutable (.0. can be string, number ar tuple) and
must be unique.
1 Aictionary is created by placing all the tems (key-value) inside
curly braces () separated by commas,
eee)
[Adding and Updating a Key-Value Pair
Sores)
focrg oa
eer
renters
[Accessing Values from a Dictionary
E The values of dictionary can be accessed by using key name inside
‘square brackets or inside gett) function
Diet = (Name: 192"
neers
Cesarean
Deseo
Dictionary Methods
keys) Returns view ofall the keys in dictionary
Retums a view ofall the values in
values) dictionary
‘Adds dletionary key-values palrs (passed
update) _as argument) to the dictionary which call
Uupdate() method
Removes and returns an element from a
PoPO)
dictionary having the given key.Dictionary Methods values()
values() methods returns a view object that splays althe values
in dictionary
Removes the arbitrary key-value palt from
amined the dictionary and returns it as tuple. Syntax
dictvalues()
copy) Returns a shallow copy ofthe dictionary
clear) Removes all the items from dictionary.
keys() lupdate()
E keys() methods returns a view object that displays all he keys
This view ob)
dictionary.
changes according othe changes inthe
LC view object ean be changed to isto tuple by using typecasting
For
re ame es
apetar
coor eet
eer]
ocstrinaserers,
aeecta)
G update() method updates the dictionary with the elements from the
another dictionary
‘Syntax
dictt update(diet2)pop()
D pop() methed removes and returns an element from a dictionary
having tho given key.
Syntax
diet pop(key_name)
ee
copy()
copy() method returns a shallow copy of the dictionary
‘syntax
dietcopy()
popitem()
E popitem() returns and removes an arbivary key-value pal rom the
detionary,
Syntax
(pase)
clear()
G clear!) method removes allthe items form dictionary.
Syntax
dict.clear()