On Oct 4, 2012 3:02 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > # populate a random matrix using both dict and list > adict = {} > alist = [[None]*2400 for i in range(2400)] > from random import randrange > for i in range(1000): > x = randrange(2400) > y = randrange(2400) > adict[(x, y)] = "something" > alist[x][y] = "something" > > import sys > print(sys.getsizeof(adict)) > print(sys.getsizeof(alist) + sum(sys.getsizeof(L) for L in alist)) > > > The actual sizes printed will depend on how sparse the matrices are, but > for the same above (approximately half full), using Python 2.7, the > figures I get are: > > adict: 24712 > alist: 23127324
I make it 0.02% full. If it was half full the dict might not have a memory advantage. Oscar
-- http://mail.python.org/mailman/listinfo/python-list