How can i access an array in a dictionary?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ruina11011

var arr : Array = [0, 0]
var dic : Dictionary = {}

after declaring the variable, use the for-loop

{0 : [0, 0], 1 : [0, 0], 2 : [0, 0], 3 : [0, 0], 4 : [0, 0], 5 : [0, 0]}

want to make a dictionary of the same type and access the array inside it.
But

for i in range :
dic[i] = arr

When declared in the form above

{0:[0, 0], 2:[…], 3:[…], 4:[…]}
{0:[0, 0], 1:[…], 10:[…], 2:[…], 3:[…], 4:[…], 5:[…], 6:[…], 7:[…], 8:[…], 9:[…]}
{0:[0, 0], 1:[…]}
{0:[0, 0], 1:[…], 10:[…], 11:[…], 12:[…], 13:[…], 2:[…], 3:[…], 4:[…], 5:[…], 6:[…], 7:[…], 8:[…], 9:[…]}

The value is stored only in the key value ‘0’.
How can I put the value of the array [0, 0] into the whole dictionary?

I know it’s possible with dic[i].i to access the dictionary in the dictionary.
But how can I access the array in the dictionary?

:bust_in_silhouette: Reply From: caprinae

It’s not entirely clear to me what you’re trying to do. What is the range you are trying to use in the for loop?

To declare a Dictionary variable, you should use the curly brace instead of the square bracket:

var dic = {}

And you would populate the dictionary with something like this:

for i in range(10):
  dic[i] = [0,0]