# space effecient representations of list subsets (question)

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Fri, 3 Dec 1993 13:01:17 -0500

I understand that in Python, assignment is usually name binding -
except in the case of assigning a part of a mutable object. i.e.

>>> a = [1,2,3]
>>> b = [0,a,4]
>>> b
[0, [1, 2, 3], 4]
>>> b[1][1] = 0
>>> b
[0, [1, 0, 3], 4]
>>> a
[1, 0, 3]

( Or try "a = [0, a, 4]" for a nice circular reference! )

And thus the difference between:

>>>c = b # "renaming" a list, or copying a reference, and
>>>c = b[:] # copying a list.

Now what I need to do is represent subsets of a sequence as a
sequence. But the sequence elements will each be rather large
text strings ( or tuple of strings. ). I assume the obvious:

sublist = [ list[0], list[4], list[22], ... list[98] ]

since it is using the values of the list, will create redundant
copies of the elements. I suppose what I need to do is create
a class wrapper ( here we go! another pseudo-sequence class! :-)
around a representation of:

MyClass.elems = [ (list,0), (list,4), (list,22), ... (list,98) ]

and an appropriate __getitem__, etc. to translate MyClass[2] into
MyClass.elem[2][0][MyClass.elem[2][1]].

However, if "list" is modified, then the indirect references of
( list, index ) become all wrong !!!

Does anyone else have any solutions or suggestions to this problem ?

I suppose I could introduce another level of indirection: create a
python version of lisp 'gensym' to create uniq names, and store and
eval those namestrings. (? does that make any sense? ) Is there some
way I can use 'id' for this sort of reference ? ( I know I can
use 'id' or 'hash' to make the symbol names --- I mean is there
any way I can reference something FROM it's id ? )

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics