Dictionaries as records

John Roth johnroth at ameritech.net
Wed Dec 19 14:49:32 EST 2001


"Bill Wilkinson" <bwilk_97 at yahoo.com> wrote in message
news:F82U7.28866$t07.4111647 at twister.midsouth.rr.com...
>
> "John Roth"
> > In this case, you have one copy of each of your input
> > strings, not 15000 copies! The memory usage should be
> > pretty close to pure dictionary overhead.
>
> I don't see how that can be. If they were all copies of the same
reference,
> wouldn't a change in one record be reflected in all?  Below I make a
change
> to one record and the others remain the same:

No. Assignment changes the object to which the variable refers,
it does not change the object that is being refered to.

In your example, the second pass created a new string object
by slicing and concatination, and then assigned it to the key in
the dictionary. It did this 15000 times.

The first pass assigned the same string (which was a literal in
the function).

John Roth






More information about the Python-list mailing list