How to store the reference of a dictionary element ?

Mike Meyer mwm at mired.org
Fri Dec 20 00:59:21 EST 2002


"Alfredo P. Ricafort" <alpot at mylinuxsite.com> writes:
> Hi Terry,
> I understand that. That is why I said in my earlier post(to Terry
> Hancock) that if I do this:
>   a['2']=[22] 
> instead of this:
>   a['2'][0]=22
> then the link will be broken.

Ok, now the solution is easy. Don't use lists. Use your own class that
look like lists:

class MenuList(list):
   def __setitem__(index, item): my[index][0] = item
   def __getitem__(index): return my[index][0]

The other methods (__setslice__, __init__, sort, insert, etc.) are
left as an exercise. The other questions being asked are also good.

        <mike

-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list