Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-07 Thread sturlamolden
On 7 Mar, 09:30, Chris Rebert wrote: > You see a tree, I see a database > (http://docs.python.org/library/sqlite3.html): > > +--+-+-+---+ > | Manufacturer | Model   | MPG | Price | > +--+-+-+---+ > | Ford         | Taurus  | ... | $...  | >

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-07 Thread TomF
On 2011-03-05 12:05:43 -0800, Paul Rubin said: Ravi writes: I can extend dictionary to allow for the my own special look-up tables. However now I want to be able to define multidimensional dictionary which supports look-up like this: d[1]['abc'][40] = 'dummy' Why do that anyway? You can us

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-07 Thread Chris Rebert
On Sun, Mar 6, 2011 at 11:06 PM, Javier wrote: > Looks a good idea.  I use this kind of "recursive dicts" to represent > tree like datastruct in python.  Like: > > car["ford"]["taurus"]["price"]=... > car["toyota"]["corolla"]["mpg"]=... > car["toyota"]["corolla"]["price"]=... > > Does anybody hav

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-06 Thread Javier
Looks a good idea. I use this kind of "recursive dicts" to represent tree like datastruct in python. Like: car["ford"]["taurus"]["price"]=... car["toyota"]["corolla"]["mpg"]=... car["toyota"]["corolla"]["price"]=... It would be good if it could be combined with class2dict (converting dict elem

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-06 Thread Ravi
That's a very nice suggestion. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread John Nagle
On 3/5/2011 12:05 PM, Paul Rubin wrote: Ravi writes: I can extend dictionary to allow for the my own special look-up tables. However now I want to be able to define multidimensional dictionary which supports look-up like this: d[1]['abc'][40] = 'dummy' Why do that anyway? You can use a tupl

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Paul Rubin
Ravi writes: > I can extend dictionary to allow for the my own special look-up > tables. However now I want to be able to define multidimensional > dictionary which supports look-up like this: > > d[1]['abc'][40] = 'dummy' Why do that anyway? You can use a tuple as a subscript: d[1,'abc',40]

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Peter Otten
Ravi wrote: > I found a solution here: > > http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional- dictionaries-in-python/ > > Please tell how good is it? Follow the link to the cookbook and read Andrew Dalke's comment ;) To spell it out: >>> class D(dict): ... def __missing_

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Ravi
I found a solution here: http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional-dictionaries-in-python/ Please tell how good is it? -- http://mail.python.org/mailman/listinfo/python-list

Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Ravi
I can extend dictionary to allow for the my own special look-up tables. However now I want to be able to define multidimensional dictionary which supports look-up like this: d[1]['abc'][40] = 'dummy' and if d[1] and d[1][abc] raise KeyError just create them. for d[1] I can override __getitem__