What am I doing wrong here? The append inside the dictionary doesn’t seem to be working
final = []
topid = {
"ida" : "ida",
"idb" : "idb",
"idc" : "idc",
"subid" : {}
}
for subid in subids:
insubid = {
"name" : subid.name,
"sida" : "sida",
"sidb" : "sidb",
"sidc" : "sidc",
}
topid["subid"].append(insubid)
final.append(topid)
I’m getting the error:
AttributeError: ‘dict’ object has no attribute ‘append’
I’m not sure this is what you want, but by using
append, your code is expectingsubidto be a list. If that’s what you are going for, you should be able to change this:to this:
Notice that
subidis now an empty list, instead of a dictionary.