Dictionaries 1 2
Dictionaries 1 2
Case sensitive
The dictionary is a mutable data type, and utilising
the right keys allows you to change its values.
Dict[key] = value and the value can both be
modified.
Adding and replacing values to a
dictionary
• To add new items in to a dictionary , we can
use the subscript [] operator.
• Syntax: Dictioanry_name [key] = value
Replacing values to a dictionary
CLEAR()
Items()
keys()
values()
get()
pop()
popitem()
fromkeys()
update()
setdefault()
Nested dictionaries
• A dictionary with in a dictionary is called nested dictionary.
Traversing Nested dictionaries
Polynomials as dictionaries
• Dictionaries can change their content so they are
mutable in nature.
• The keys in a dictionary is not restricted to be strings.
• Any immutable object can be used as key.
• A common type of key used in dictionaries is integers.
• We can use dictionaries while calculating polynomial
equation.
• A dictionary is used to map a power to a coefficient.
let the equation be -2 + y^4 + 3y^6
The dictionary for the above equation is
{0:-2, 4:1, 6:3}
Write a python program to calculate the polynomial
equation -2 + y^4 + 3y^6