How to store the reference of a dictionary element ?

Bengt Richter bokr at oz.net
Tue Dec 17 17:36:41 EST 2002


On 17 Dec 2002 12:53:26 +0800, "Alfredo P. Ricafort" <alpot at mylinuxsite.com> wrote:

>Not quite, but I can live with it if there are no more simple solution.
>
>I am really planning to implement the 'values' as list.  They are
>actually attributes of a record. But my problem with this code is if I
>mistakenly do this:
>
>  a['2']=[22] 
>
>instead of 
>
>  a['2'][0]=22
>
>then the link would be broken and I would end up with an orphan child in
>my linked list. Currently, the number of attributes are not that many so
>I can still afford to subscript each element during assignment.
>
I tried to understand "what you are *really* trying do do"(tm) but couldn't ;-)
If you would define your requirements independently of preconceived implementation
ideas, I suspect people would be able to help better.

I.e., what are the entities you are concerned with, what are their relationships,
what entities are composite, which are primitive atoms, what operations
of de/composition do you want to do, what is the life cycle of your entities,
which must persist, what interactive views do you need, etc., etc.

Even mentioning a programming language is not necessary to do that, although of
course legal Python that actually does what you want **somehow** is an excellent
way to be specific, and incomplete but legal code is also good, with "# magic here"
comments. If you start with a class definition of your own instead of
trying to force behaviour of builtins, it will give you more freedom to express
your intent. Just start with class MBB(object): and define the Magic Black Box
thing that you want, giving it methods to do what you want, and class and instance
attributes to keep state info appropriate to each. Instead of a dictionary or a list,
start with the MBB ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list