[Tutor] Why do sets use 6 times as much memory as lists?
Dave Angel
davea at davea.name
Tue May 7 19:39:46 CEST 2013
On 05/07/2013 01:10 PM, Bjorn Madsen wrote:
>>>> import sys
>>>> L=[x for x in range(10000)]
>>>> sys.getsizeof(L)
> 43816
>>>> L={x for x in range(10000)}
>>>> sys.getsizeof(L)
> 262260
> ?
> kind regards,
> Bjorn
>
>
Just curious: what did you expect? Sets have a different purpose,
basically to be able to do an 'in' operation instantly, while lists have
to scan every item in the list.
I figure the ratio to be more like 75% larger, since the 10,000 objects
are going to take up maybe 24 bytes each.
--
DaveA
More information about the Tutor
mailing list