fastest data structure for retrieving objects identified by (x,y) tuple?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 4 19:37:47 EDT 2012


On Thu, 04 Oct 2012 18:11:28 +0200, Thomas Rachel wrote:

> Am 04.10.2012 03:58 schrieb Steven D'Aprano:
>> 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"
> 
>> The actual sizes printed will depend on how sparse the matrices are,
>> but for the same above (approximately half full),
> 
> I wouldn't consider 1000 of 5760000 "half full"...

Doh! I obviously can't multiply...

I mean, well done, that was a deliberate test to see who was paying 
attention, and you passed! 

:)


-- 
Steven



More information about the Python-list mailing list