When to clear a dictionary...

Bill Jackson jackson at hotmail.com
Fri Apr 20 12:48:07 EDT 2007


What is the benefit of clearing a dictionary, when you can just reassign 
it as empty?  Similarly, suppose I generate a new dictionary b, and need 
to have it accessible from a.  What is the best method, under which 
circumstances?

 >>> import some_function

 >>> a = {1:2,3:4}
 >>> b = {1:2:4:3}
 >>> a.clear()
 >>> a.update(b)

 >>> a = {1:2,3:4}
 >>> b = {1:2,4:3}
 >>> for key in b:
...     a[key] = b[key]

 >>> a = {1:2,3:4}
 >>> b = {1:2,4:3}
 >>> a = b




More information about the Python-list mailing list