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

2012-10-04 Thread Steven D'Aprano
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" >>

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

2012-10-04 Thread Thomas Rachel
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 h

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

2012-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2012 08:21:13 -0400, Benjamin Jessup wrote: > On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: >> How do you know that? >> >> No offence, but if you can't even work out whether lookups in a dict or >> a list are faster, I can't imagine why you think you can intuit what >

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

2012-10-04 Thread Benjamin Jessup
On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: How do you know that? No offence, but if you can't even work out whether lookups in a dict or a list are faster, I can't imagine why you think you can intuit what the fastest way to retrieve the nearest neighbours would be. Whats wro

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

2012-10-04 Thread Oscar Benjamin
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 = randran

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

2012-10-03 Thread Steven D'Aprano
On Thu, 04 Oct 2012 01:58:16 +, Steven D'Aprano wrote: > adict: 24712 > alist: 23127324 [...] > So in this situation, a list of lists uses about 100 times > more memory than a dict, but look-ups are about 6% faster. Correction: about 1000 times more memory. Sorry for the typo. -- Steven -

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

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 18:30:24 -0400, Benjamin Jessup wrote: > I have a group of objects identified by unique (x,y) pairs and I want to > find out an object's "neighbors" in a matrix of size 2400 x 2400. [...] > There is either a neighbor, or a null value. I always know the (x,y) > pair to check the

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

2012-10-03 Thread Joshua Landau
On 3 October 2012 23:30, Benjamin Jessup wrote: > I have a group of objects identified by unique (x,y) pairs and I want to > find out an object's "neighbors" in a matrix of size 2400 x 2400. ># >#obj# # # ># ># # #obj# 3 x 3 Exa

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

2012-10-03 Thread Benjamin Jessup
I have a group of objects identified by unique (x,y) pairs and I want to find out an object's "neighbors" in a matrix of size 2400 x 2400. # #obj# # # # # # #obj# 3 x 3 Example # # # # # ##