| |
| | How to think like a Pythonista (Site not responding. Last check: 2007-10-22) |
 | | >>> dict = {'a':[1],'b':[2]} >>> list = dict.values() >>> list [[1], [2]] >>> dict['a'].append(3) >>> dict {'a': [1, 3], 'b': [2]} >>> list [[1, 3], [2]] Looks like that in the first case a copy is returned while in the latter case list references are returned. |
 | | It works, but of course it can never be as fast as the mundane business of shallow copying (which in turn is never as fast as just handing out one more reference to an existing object, whenever the latter course of action is feasible). |
 | | Not really -- if you change _objects to which the dict refers_ (rather than changing the dict in se), then other references to just-the-same-objects remain references to just the same objects -- if the objects mutate, you see the mutated objects from whatever references to them you may be using. |
| starship.python.net /crew/mwh/hacks/objectthink.html (2423 words) |
|