In this python dictionary program, we will get the size of a dictionary in python using sys library.
Steps to solve the program
- Import the sys library.
- Take a dictionary as input.
- Get the size of a dictionary using sys.getsizeof().
- Print the output.
import sys
D1 = {'name':'virat','sport':'cricket'}
print("Size of dic1: " + str(sys.getsizeof(D1)) + "bytes")
Output :
Size of dic1: 232bytes