#How to fill() an array with separate but identical dictionaries

8 messages · Page 1 of 1 (latest)

toxic lake
#

I have an array, called archive.
I want to use the fill() function to fill it with dictionaries.
I want each element in archive to be a separate dictionary, although they should all have the same values.

The documentation for fill() says that if a dictionary is passed in as an argument, then the array will be filled with references to the same dictionary. I don't want that. I want references to unique dictionaries.

I tried to use duplicate(), but it didn't work. I still get references to the same dictionary. What do I need to do differently?

This is my code:

#

I fixed it by not using fill(). I just did a for loop for the same effect. This is the code I used instead to fix it:

#

What's the point of duplicate() when I can just write dictionary1 = dictionary2?

#

I did some research and apparently duplicate() fails at nested objects

south apex
#

duplicate(true) should still properly duplicate itself and all of its nested dictionaries & arrays.
What fill() do:
Take the reference to whatever you give it, and assign it to all of its entries. Meaning, all of the array's entries will directly reference the same thing
(unless that thing is a value-type, like integer, bool, float, etc. Then it is not set by reference)

toxic lake
#

Oh, so they all got the same duplicated object, meaning the same reference

south apex
#

yep