Re: searching a value of a dict (each value is a list)

2007-12-14 Thread MonkeeSage
On Dec 10, 1:28 pm, [EMAIL PROTECTED] wrote: > Seongsu Lee: > > >I have a dictionary with million keys. Each value in the dictionary has a > >list with up to thousand integers.< > > Let's say each integer can be represented with 32 bits (if there are > less numbers then a 3-byte representation may

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread bearophileHUGS
Seongsu Lee: >I have a dictionary with million keys. Each value in the dictionary has a list >with up to thousand integers.< Let's say each integer can be represented with 32 bits (if there are less numbers then a 3-byte representation may suffice, but this makes things more complex), that is 2^2

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread MonkeeSage
On Dec 10, 9:45 am, MonkeeSage <[EMAIL PROTECTED]> wrote: > On Dec 10, 8:31 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > > > > On 2007-12-10, MonkeeSage <[EMAIL PROTECTED]> wrote: > > > > If I'm not mistaken, building a reverse dictionary like that will be > > > O(n*m) because dict/list access i

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread MonkeeSage
On Dec 10, 8:31 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-12-10, MonkeeSage <[EMAIL PROTECTED]> wrote: > > > If I'm not mistaken, building a reverse dictionary like that will be > > O(n*m) because dict/list access is O(n) (ammortized). Somebody correct > > me if I'm wrong. In that case,

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread MonkeeSage
On Dec 10, 8:31 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-12-10, MonkeeSage <[EMAIL PROTECTED]> wrote: > > > If I'm not mistaken, building a reverse dictionary like that will be > > O(n*m) because dict/list access is O(n) (ammortized). Somebody correct > > me if I'm wrong. In that case,

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread Neil Cerutti
On 2007-12-10, MonkeeSage <[EMAIL PROTECTED]> wrote: > If I'm not mistaken, building a reverse dictionary like that will be > O(n*m) because dict/list access is O(n) (ammortized). Somebody correct > me if I'm wrong. In that case, it really depends on how you will use > the dict to see whether you g

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread MonkeeSage
On Dec 10, 3:50 am, Seongsu Lee <[EMAIL PROTECTED]> wrote: > On 12월10일, 오후12시18분, Adonis Vargas <[EMAIL PROTECTED]> > wrote: > > > > > Seongsu Lee wrote: > > > Hi, > > > > I have a dictionary with million keys. Each value in the > > > dictionary has a list with up to thousand integers. > > > Follow

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread Seongsu Lee
On 12월10일, 오후12시18분, Adonis Vargas <[EMAIL PROTECTED]> wrote: > Seongsu Lee wrote: > > Hi, > > > I have a dictionary with million keys. Each value in the > > dictionary has a list with up to thousand integers. > > Follow is a simple example with 5 keys. > > > dict = {1: [1, 2, 3, 4, 5], > >2: [

Re: searching a value of a dict (each value is a list)

2007-12-10 Thread bearophileHUGS
Adonis Vargas: > Also, you should never use reserved words like 'dict' this creates > confusion and can cause Python to misbehave since you are rebinding the > name. > Adonis Vargas After hearing this suggestion for the 300th time, I think it may be the moment to fix this problem in Python3, and m

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Adonis Vargas
Seongsu Lee wrote: > Hi, > > I have a dictionary with million keys. Each value in the > dictionary has a list with up to thousand integers. > Follow is a simple example with 5 keys. > > dict = {1: [1, 2, 3, 4, 5], >2: [10, 11, 12], >90: [100, 101, 102, 103, 104, 105], >91: [20

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Jeremy C B Nicoll
Seongsu Lee <[EMAIL PROTECTED]> wrote: > The reason I use the dict for my data is to speed up the search by key. Ok, I understand that once the overhead of creating the dict has been done, getting access to values within it is quick. And taking the time to create a set of reverse keys speeds up

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Seongsu Lee
On 12월10일, 오전6시49분, Jeremy C B Nicoll <[EMAIL PROTECTED]> wrote: > Seongsu Lee <[EMAIL PROTECTED]> wrote: > > Hi, > > > I have a dictionary with million keys. Each value in the > > dictionary has a list with up to thousand integers. > > Follow is a simple example with 5 keys. > > > dict = {1: [1, 2

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Zepo Len
> I have a dictionary with million keys. Each value in the > dictionary has a list with up to thousand integers. > Follow is a simple example with 5 keys. > > dict = {1: [1, 2, 3, 4, 5], >2: [10, 11, 12], >90: [100, 101, 102, 103, 104, 105], >91: [20, 21, 22], >99: [15,

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Jeremy C B Nicoll
[EMAIL PROTECTED] wrote: > Jeremy C B Nicoll: > > The code someone else posted ... > > If you are talking about my D code then I know it... No I meant the code that used python to iterate over the dict and create zillions of extra keys. I've deleted earlier posts in the thread and wasn't sure w

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread bearophileHUGS
Jeremy C B Nicoll: > The code someone else posted to reverse the keys is all very well, but > surely hugely wasteful on cpu, maybe storage, and elapsed time. If you are talking about my D code then I know it, the creation of the first dict has to be skipped, if possible... The code I have posted m

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Jeremy C B Nicoll
Seongsu Lee <[EMAIL PROTECTED]> wrote: > Hi, > > I have a dictionary with million keys. Each value in the > dictionary has a list with up to thousand integers. > Follow is a simple example with 5 keys. > > dict = {1: [1, 2, 3, 4, 5], >2: [10, 11, 12], >90: [100, 101, 102, 103, 104, 1

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread bearophileHUGS
Seongsu Lee: > What do you think of this? Ideas with less space complexity? You can put the second group of keys in a second dictionary, so you don't have to mangle them, and it may be a bit faster. Regarding the space complexity, I don't know how you can reduce it with Python. Probably you can c

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Bruno Desthuilliers
Seongsu Lee a écrit : > Hi, > > I have a dictionary with million keys. Each value in the > dictionary has a list with up to thousand integers. > Follow is a simple example with 5 keys. > > dict = {1: [1, 2, 3, 4, 5], >2: [10, 11, 12], >90: [100, 101, 102, 103, 104, 105], >91:

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Seongsu Lee
On 12월10일, 오전1시53분, Pablo Ziliani <[EMAIL PROTECTED]> wrote: > Seongsu Lee escribió: > > > Hi, > > > I have a dictionary with million keys. Each value in the > > dictionary has a list with up to thousand integers. > > (...) > > > I want to find out the key value which has a specific > > integer in

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Seongsu Lee
On 12월10일, 오전1시23분, Seongsu Lee <[EMAIL PROTECTED]> wrote: > Hi, > > I have a dictionary with million keys. Each value in the > dictionary has a list with up to thousand integers. > Follow is a simple example with 5 keys. > > dict = {1: [1, 2, 3, 4, 5], >2: [10, 11, 12], >90: [100, 101,

Re: searching a value of a dict (each value is a list)

2007-12-09 Thread Pablo Ziliani
Seongsu Lee escribió: > Hi, > > I have a dictionary with million keys. Each value in the > dictionary has a list with up to thousand integers. > (...) > > I want to find out the key value which has a specific > integer in the list of its value. Sorry if this is unhelpful, but have you considered m

searching a value of a dict (each value is a list)

2007-12-09 Thread Seongsu Lee
Hi, I have a dictionary with million keys. Each value in the dictionary has a list with up to thousand integers. Follow is a simple example with 5 keys. dict = {1: [1, 2, 3, 4, 5], 2: [10, 11, 12], 90: [100, 101, 102, 103, 104, 105], 91: [20, 21, 22], 99: [15, 16, 17, 18,