Intelligent datastructure?
Aahz Maruch
aahz at netcom.com
Sun Sep 26 11:50:42 EDT 1999
In article <y0jaeqhejn4.fsf at vier.idi.ntnu.no>,
Magnus L. Hetland <mlh at idt.ntnu.no> wrote:
>
>I only have two datatypes - integers and sequences. The thing I have
>been thinking about lately is the implementation of the sequences. I
>want them to be usable both as simple lists or arrays, and as general
>hash-tables (with numeric keys) without the user having to care about
>the difference... Thus, you could make yourself a sequence like this:
>
> s = [1,2,3]
>
>and then do something like
>
> s[100] = 4
>
>without getting any complaints. (I think I will only allow positive
>integers as indices, but I'm not sure...)
>
>If I now reference s[50], for instance, or s[400], I would like to get
>0, which is the default value for all variables (or elements).
>
>I would like feedback on that strategy (of basically allowing anything
>to be done without throwing index-exceptions or stuff like that), but
>what I am mainly interested in is the task of making these sequences
>"intelligent".
Being generally interested in simple code, if I were in your shoes I'd
probably just use a dict-based class.
--
--- Aahz (@netcom.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6 (if you want to know, do some research)
More information about the Python-list
mailing list