Can I use .append to add a Dictionary var to an existing Array?

Godot Version

4.7.2

Can I use .append to add a Dictionary var to an existing Array?

Hi, I am really new to Godot and GDScript specifically so I decided to try and recreate Poker to start, how can I then access each single Dict inside of my array, to print all of the cards?

When I then print using print(“deck”) it only shows 13 of Spades, but I figured that is just Godot reprinting only the last value of the array

extends Node2D

signal draw_card()

#Array di dizionari
var card: Dictionary = {"Suit" : 0, "Value" : 0}
var deck: Array = [card]

var suits = ["Clubs", "Diamonds", "Hearts", "Spades"]
var values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

func _ready() -> void:
	initialize_deck()

func initialize_deck():
	
	for i in suits:
		for j in values:
			card["Suit"] = i
			card["Value"] = j
			deck.append(card)

You need to create a new dictionary for each card. Currently you’re just changing the values in the same dictionary and append a reference to the same thing over and over.

I figured that would’ve been the case and actually solved it by creating a new dictionary for each loop, like this

func initialize_deck():
for i in suits:
for j in values:
var inserted_card: Dictionary = {“Suit” : 0, “Value” : 0}
inserted_card[“Suit”] = i
inserted_card[“Value”] = j
deck.append(inserted_card)

then I realized I can just ditch the variable entirely and went with

for i in suits:
for j in values:
deck.append({"Suit": i, "Value": j})