Python Forum
size of set vs size of dict - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: size of set vs size of dict (/thread-21714.html)



size of set vs size of dict - zweb - Oct-11-2019

>>> n = 10000
>>> s = {x for x in range(n)}
>>> sys.getsizeof(s)
524512
>>> d = {x:1 for x in range(n)}
>>> sys.getsizeof(d)
295008

I would have expected size of set to be smaller than dict. But when I run such tests for different n I find frequently size of set is bigger. Why would be that be?