Python Forum

Full Version: size of set vs size of dict
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
>>> 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?