function calls ...

brueckd at tbye.com brueckd at tbye.com
Tue Aug 20 15:57:30 EDT 2002


On Tue, 20 Aug 2002, Axel Bock wrote:

> Now I have a special problem: I have a dictionary, and I have a function.
> And I want to call the function with the dictionary as parameter, but I
> want a *COPY* of the dictionary be transferred, cause the function makes
> changes to this one which I don't like to keep but are nonetheless
> neccessary.
> 
> With lists it works like this:
> 	callme(list[:])
> but with dictionaries ... ?

Well, do you want a copy of the dictionary or a copy of the dictionary and 
a copy of all of its members too? To get the same behavior as above with 
the list, use the dictionary's copy member:

>>> a = {'foo':5}
>>> b = a.copy()

If you want copies of everything use the copy module's deepcopy function.

-Dave





More information about the Python-list mailing list