Counterintuitive Python behavior
Alex Martelli
aleax at aleax.it
Wed Apr 17 10:22:19 EDT 2002
dominikush at yahoo.com wrote:
...
> I understand that! But my main objection remains: Why should
> I care about the type of object being handled by a dictionary?
You shouldn't: whatever types of objects are the dictionary's values,
method .values() will ALWAYS return a new list object whose items
refer to EXACTLY the same objects as the dictionary's values.
> This could not only break unit tests but also make maintenance
> of ``old'' code somewhat painful.
I don't understand what you're talking about. My sentence above
was true at least since Python 1.5.2 (probably earlier, but that's
when I hopped aboard).
Alex
More information about the Python-list
mailing list