In the game engine why do variables link clists from globalDict instead of copying them?
this_is_a_list = [0,1,2,3,4]
this_points_to_the_same_data = this_is_a_list
this_copies_an_item_from_the_list = this_is_a_list[1]


A list (or array, dictionary, object...) is a composite type that may contain thousands of items and could consume a GB of ram, assigning a composite type to a new variable only assigns a value that points to the same data as the original variable. You need to manually copy the entire item if that is what you desire.

It may also help to understand that this_is_a_list is only a pointer or reference to where the data is stored in ram, the [] is used to specify which part of the ram used by the object you wish to read. So using = is assigning the same reference to the new variable.

This is mostly a performance decision (it is the way python works not just blender), a single number consumes a similar amount (dependant on the number and 32/64 bit system being used) of ram as a pointer to a large composite data type. These values can easily be passed between functions within the cpu without any performance penalty. Copying an entire compound data type can consume large amounts of ram and take seconds to copy, so is not performed unless you specifically want to copy the entire thing.

To get a full copy you can use copy()

this_copies_the_entire_list = this_is_a_list.copy()


copy() is useful as it can be used for lists and dictionaries. For lists you can also copy them with blist = alist[:] or blist = [x for x in alist] which also allows you to add an if test to copy part of the list.