Re: nested structure with "internal references"



On Sep 25, 10:11 am, Torsten Mohr <tm...@xxxxxxxxxx> wrote:
Hi,

sorry for posting in german before, that was a mistake.

I'd like to use a nested structure in memory that consists
of dict()s and list()s, list entries can be dict()s, other list()s,
dict entries can be list()s or other dict()s.

The lists and dicts can also contain int, float, string, ...

But i'd also like to have something like a "reference" to another
entry.
I'd like to refer to another entry and not copy that entry, i need to
know later that this is a reference to another entry, i need to find
also access that entry then.

Is something like this possible in Python?

The references only need to refer to entries in this structure.
The lists may change at runtime (entries removed / added), so
storing the index may not help.

Hmm, I think I understand what you're asking but I don't think there's
an easy way.

Probably the most straightforward way is to use "cells" of some sort
to contain the entries in a list or dict; then take references to the
cells. That way you can change the cell's value while still
maintaining the reference. For instance, suppose you have a list like
this:

lst = [ 1, 2, 3, 4 ]

Convert it to this:

lst = [ [1], [2], [3], [4] ]

where you are using a nested singleton list as the cell type. Then,
you can take a reference like this:

ref = lst[2]

If you insert an item into the list, the reference remains valid:

lst.insert(0,[0])

And, if you change the value of the cell, the reference will see the
updated value.

lst[3][0] = 5

The downside is that you have to add [0] everywhere. The reference's
value is ref[0], not just ref. The third item in the list is lst[2]
[0], not just lst[2]. You could define custom list- and dict-like
classes that automatically do this, mitigating the problem somewhat.

I hope you could understand that suggestion, it's tough to describe.


Other than that, you are stuck with massive use of Observer pattern
(you'd have to create list- and dict-like types that know when
something is referencing them, and that notify the references whenever
they change).


Carl Banks
.



Relevant Pages

  • Re: Solving the lib mismatch problem
    ... This section is pointed to by an entry in the section table with the ... The number of entries in the table is determined by DT_VERDEFNUM. ... This is an index into the string section referenced in the section ... Offset in the string section reference by the link in the section ...
    (comp.unix.programmer)
  • Re: Autoruns
    ... It's impossible for AutoRuns to keep a database of all software available and what you may have installed on your system and then uninstalled (with the uninstalled software not deleting it's own entries from the registry properly or completely), or indeed what 3rd party software is essential at boot-up and what isn't. ... It's just a matter of going through the categories in AutoRuns and also looking in Task Manager's Processes list and/or using the similar lists, but with full path info., from the system info. freeware program 'Everest' which you can find and download with a google search and will help you identify which entries belong to which software packages by virtue of the full path. ... Finally don't delete an entry from AutoRuns, just uncheck it so that it is restorable later. ...
    (microsoft.public.windowsxp.general)
  • Re: nested structure with "internal references"
    ... dict entries can be lists or other dicts. ... The lists and dicts can also contain int, float, string, ... ... But i'd also like to have something like a "reference" to another ... I'd like to refer to another entry and not copy that entry, ...
    (comp.lang.python)
  • Re: a benefit to using a linked list in insertion sort?
    ... >> Use linked lists to make insertions easy, ... >> isn't a binary search at all but a hash table. ... You "probe" the entry at this index. ... rather than having to insert and move subsequent entries as ...
    (comp.programming)
  • Re: Cross Referencing Lists (REVISED)
    ... of entries in column A to be reduced as follows. ... there is an entry in column A that has an entry in column B ... >>Frank Kabel ... >>>>> confusing perhaps I can email the 2 lists to someone ...
    (microsoft.public.excel.worksheet.functions)

Loading