Python program to get the size of a dictionary.

In this python dictionary program, we will get the size of a dictionary in python using sys library.

Steps to solve the program
  1. Import the sys library.
  2. Take a dictionary as input.
  3. Get the size of a dictionary using sys.getsizeof().
  4. Print the output.
				
					import sys
D1 = {'name':'virat','sport':'cricket'}

print("Size of dic1: " + str(sys.getsizeof(D1)) + "bytes")
				
			

Output :

				
					Size of dic1: 232bytes
				
			

get the sum of all the items in a dictionary.

check whether a key exists in the dictionary or not.

Leave a Comment