What would be the difference between using a copy
and a defaultdict
approach for the below?
base_data = {...}
for item in iterable:
# approach 1 <-- why wouldn't this work?
data = defaultdict(lambda: base_data)
# approach 2
data = deepcopy(base_data)
...
It seems the first method is the wrong object type for this, but could someone clarify what the difference is between the two approaches, and why that wouldn't work?
defaultdict
, so usedeepcopy
– azro Oct 29 '20 at 17:08base_data
s (each being the same object, by the way), the second is just the equivalent of a singlebase_data
. – MisterMiyagi Oct 29 '20 at 17:10