[Tutor] Dictionary to variable copy
*Can i copy the content if a dictionary in to another variable, with out any link between the dictionary the variable? if so, please teach. * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionary to variable copy
Op 08-12-11 10:03, sunil tech schreef: /Can i copy the content if a dictionary in to another variable, with out any link between the dictionary the variable? / Have a look at the copy module [1], or use the builtin dict.copy() method. Cheers, Timo [1] http://docs.python.org/library/copy.html#module-copy / if so, please teach. / ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionary to variable copy
On 08/12/11 09:03, sunil tech wrote: /Can i copy the content if a dictionary in to another variable, with out any link between the dictionary the variable? if so, please teach. Yes, but they will both refer to the same object. But the two references will be entirely independant: D = {1:2,3:4} d = D[1] # both d and D[1] reference 2 D[1] = 42 # d still refers to 2 del(D) # d still refers to 2 Is that what you mean? Or do you wantbto make a clone of the value so that you can change it without changing the original? In that case you can use several techniques depending on object type. Generically use copy or deepcopy. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor