Is Python set more space efficient than list?
python
Solution
>>> from sys import getsizeof as size
>>> s = set(xrange(100))
>>> l = list(xrange(100))
>>> size(s)
8424
>>> size(l)
1016
`set`s take up more memory than `list`s. Some of the functionality that `set`s offer requires more memory (e.g. quick membership tests).
Problem
`list` is known to initialize with a big chunk of space to optimize the time needed to expand the list (on average we don't have to keep making new list like an array). What about `set`? The following construction makes it space wasted because of `list`. I understand `tuple` is more space saving because it is immutable. Can we do the same to `set` and still mutable? `set( [ 1, 2, 3] )`