Question about dictionaries (Question about is ?)

Felix Thibault felixt at dicksonstreet.com
Sat Jan 8 12:30:31 EST 2000


At 11:21 1/8/00 -0500, Matt Gushee wrote:
<snip my question>
>I'm not sure what it means either, but what seems to be happening is
>that dict1['spam'].keys()[0] returns a reference to text[-5:-1] --
>i.e.:
>
>        'spam-a-lam-a-spama'
>                    ^^^^
>whereas dict2['spam'].keys()[0] returns a reference to text[:4], --
>i.e.:
>
>        'spam-a-lam-a-spama'
>         ^^^^
>... and the two just happen to have the same string value. 
>
>>>> dict1.keys()[0] == dict1['spam'].keys()[0]
>1
>
>> does dict2
>> take up less memory,
>
>I don't know enough about the internals of Python to be sure, but I
>can't imagine it would. dict1 references two different objects with
>the value 'spam'; dict2 references a single spammy object twice; but
>they both contain the same number of object references.
>
>> or something, or is this just a Stupid Programming
>> Trick?
>
>Hah! Your next challenge is to find a use for this interesting
>technique. If you can do that, it won't be just a Stupid Programming
>Trick ;-)

Well the use I have is building a nested dictionary out of 
some HTML...near the beginning of the program I make 
a dictionary with the tags in the document for keys, so 
it's easy to make everything downhill from that point to the
same 20 or so slices of the document instead of pointing
to hundreds ... Which is simpler for me to think about, but
I'm getting the idea that the computer doesn't care.

>
>-- 
>Matt Gushee
>Portland, Maine, USA
>mgushee at havenrock.com
>http://www.havenrock.com/
>-- 
>http://www.python.org/mailman/listinfo/python-list
>

Thanks-
	Felix





More information about the Python-list mailing list