Dictionary Length in Python
To find out the length of a dictionary, you should apply the len function:
dct = {
'a': 1,
'b': 2,
'c': 3
}
print(len(dct)) # 3
Given a dictionary:
dct = {
'x': 1,
'y': 2,
'z': 3
}
Find out the number of elements in it.
The following dictionaries are given:
dct1 = {
'a': 12,
'b': 34,
'c': 56,
'd': 78,
'e': 90
}
dct2 = {}
Add an element to the second dictionary whose key is the name of the first dictionary and whose value is its length.