Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread Dave Angel
On 05/07/2013 01:10 PM, Bjorn Madsen wrote: import sys L=[x for x in range(1)] sys.getsizeof(L) 43816 L={x for x in range(1)} 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'

Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread Oscar Benjamin
On 7 May 2013 18:10, Bjorn Madsen bjorn.h.mad...@googlemail.com wrote: import sys L=[x for x in range(1)] sys.getsizeof(L) 43816 L={x for x in range(1)} sys.getsizeof(L) 262260 Firstly, these results may vary depending on operating system, processor architecture and build options

Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread Bjorn Madsen
Hi, Thanks for the quick response. Being curious I actually expected something like this: L={x:None for x in range(1)} sys.getsizeof(L) 196660 That is why I wondered why 6 times is a lot given that a dict can do the same at 3/4 of the mem-footprint. Just got surprised about the overhead

Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread Oscar Benjamin
On 7 May 2013 19:09, Bjorn Madsen bjorn.h.mad...@googlemail.com wrote: Hi, Thanks for the quick response. Being curious I actually expected something like this: L={x:None for x in range(1)} sys.getsizeof(L) 196660 That is why I wondered why 6 times is a lot given that a dict can do

Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread Steven D'Aprano
On 08/05/13 03:10, Bjorn Madsen wrote: import sys L=[x for x in range(1)] sys.getsizeof(L) 43816 L={x for x in range(1)} sys.getsizeof(L) 262260 ? Both sets and lists may be over-allocated. I expect that lists created with a list comprehension may not be over-allocated, but if you

Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread eryksun
On Tue, May 7, 2013 at 2:09 PM, Bjorn Madsen bjorn.h.mad...@googlemail.com wrote: Being curious I actually expected something like this: L={x:None for x in range(1)} sys.getsizeof(L) 196660 That is why I wondered why 6 times is a lot given that a dict can do the same at 3/4 of the

Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread eryksun
On Tue, May 7, 2013 at 9:30 PM, eryksun eryk...@gmail.com wrote: That is why I wondered why 6 times is a lot given that a dict can do the same at 3/4 of the mem-footprint. I hope it's clear that 3/4 here comes from 1/2 * 3/2. In other words the dict table has 1/2 the number of entries, and

Re: [Tutor] Why do sets use 6 times as much memory as lists?

2013-05-07 Thread wesley chun
Following Oscar's comment, It's also O(n) vs. O(1) tradeoff. --wesley On Tue, May 7, 2013 at 12:09 PM, Oscar Benjamin oscar.j.benja...@gmail.comwrote: On 7 May 2013 19:09, Bjorn Madsen bjorn.h.mad...@googlemail.com wrote: Hi, Thanks for the quick response. Being curious I actually