I have a Python program that works with dictionaries a lot. I have to make copies of dictionaries thousands of times. I need a copy of both the keys and the associated contents. The copy will be edited and must not be linked to the original (e.g. changes in the copy must not affect the original.)
Keys are Strings, Values are Integers (0/1).
I currently use a simple way:
newDict = oldDict.copy()
Profiling my Code shows that the copy operation takes most of the time.
Are there faster alternatives to the dict.copy()
method? What would be fastest?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…