Question about dictionaries (Question about is ?)

Felix Thibault felixt at dicksonstreet.com
Wed Jan 5 22:56:35 EST 2000


Hi Everybody-

I've been working with nested dictionaries whose keys are slices of text
from a document, and I've come up with two ways to make them:

>>> text = 'spam-a-lam-a-spama'
>>> names = {'spam': text[:4]}
>>> dict1 = {text[:4]: {text[-5:-1]: 'eggs'}}
>>> dict2 = {names[text[:4]]: {names[text[-5:-1]]: 'eggs'}}

with the difference being:

>>> dict1.keys()[0] is dict1['spam'].keys()[0]
0
>>> dict2.keys()[0] is dict2['spam'].keys()[0]
1

...but I'm new to programming as well as to Python, so I'm not sure what
this means- does dict2
take up less memory, or something, or is this just a Stupid Programming
Trick? Is this like 
intern(..)'ing ? 


Thanks in advance,

Felix







More information about the Python-list mailing list