0

How to append an array with a dictionary inside a dictionary?

d1 = {
'a':'a',
'b':'b'
}

d2 = {
'c':'c',
'd':'d'
}

maindict = {
'1':'1',
'array':[] #append d1, d2 here
}

to be like

maindict = {
'1':'1',
'array':[d1, d2, ...] #append d1, d2 here
}

maindict = {
'1':'1',
'array':[{},{}, ...] #append d1, d2 here
}
Majoris
  • 2,963
  • 6
  • 47
  • 81

1 Answers1

3

You append to it like you would any other array, with .append:

maindict['array'].append(d1)

maindict['array'].append(d2)
Lord Elrond
  • 13,430
  • 7
  • 40
  • 80