+ 1

How to define a dictionary size?

Like we define in list

21st Jun 2021, 3:39 AM
Zahed Shaikh
Zahed Shaikh - avatar
3 Answers
+ 6
Zahed Shaikh I don't think you need to define a size of dictionary or list. We initialise dictionary or list like this: dictionary = {} list1 = [] So there is no need to define size. You can add elements as many you want but If you want restrict user to add defined size of data you can just validate it after getting size of dictionary or list.
21st Jun 2021, 4:02 AM
A͢J
A͢J - avatar
+ 2
Zahed Shaikh "You mean how to get size"? Same as list : dictionary = {1 : 2, 3 : 4} print(len(dictionary))
21st Jun 2021, 3:52 AM
A͢J
A͢J - avatar
0
Can we set a predefined dictionary size
21st Jun 2021, 3:54 AM
Zahed Shaikh
Zahed Shaikh - avatar