Re: Swapping Content of Two Dictionaries.

2010-03-17 Thread Steven D'Aprano
On Wed, 17 Mar 2010 13:34:51 +0100, Peter Otten wrote: > Hatem Oraby wrote: > >> Hello, I want to swap the content of two dictionaries, the obvious way >> to do it is: >> a = {1:"I'am A"} >> b = {2:"I'm B"} >> temp = a >> a = b >> b = temp > > That can be simplified to > > a, b = b, a > > and

Re: Swapping Content of Two Dictionaries.

2010-03-17 Thread Stefan Behnel
Hatem Oraby, 17.03.2010 12:26: However, consider the case in which the dictionary we are referencing lives in another module: #external.py # #a = {1:"I'am A} import external temp = external.a external.a = b b = temp Looks like the interface of your module is broken. It shouldn't export the tw

Re: Swapping Content of Two Dictionaries.

2010-03-17 Thread Peter Otten
Hatem Oraby wrote: > Hello, I want to swap the content of two dictionaries, the obvious way to > do it is: > a = {1:"I'am A"} > b = {2:"I'm B"} > temp = a > a = b > b = temp That can be simplified to a, b = b, a and is almost certainly the right approach. > tempKeys = a.keys() > diffKeys = a.k