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