I recall reading that from Python 3.6+ dictionaries would be ordered so I figured that it would hold true for updating/merging dictionaries as well. Unfortunately when I run my code, my output has a jumbled mess of key:value pairs while I thought I would keep the order and just append onto the back of the dictionary like list.append().
Originally I was using the dictonary1.update({dict2_key:dict2:val}), but I've also tried the geeksforgeeks merge as well as kwargs option, but it's still giving me a jumbled mess. I can't use the 3.9 union "dict1|dict2" as my work interpreter is 3.8 and updating is a whole mess.
Any resources I could look into to getting my dictionaries to just...tack on at the end? Or would that involve making them all lists, appending them, and then reverting it back to a dictionary again?
Edit: Anonymized sample of my dictionary outputs:
result = [{dict1},{dict2},{dict3},{dict4:[dict5,dict6]}]
output = {}
for item in result:
for key in item.keys():
if key == dict4["key"]:
pass
else:
output[key] = item[key]
for parameter in item["dict4[key]"]:
function(parameter) #[changes the string of the keys][4]#using andidogs python 3 version
output = {**output,**parameter}
print(output, "\n")
print(output, "\n")
#1 record of output:
{#first item of dict1, #contents dict5, #contents of dict6, #second item of dict1, #contents of dict2}
#desired output:
#{#contents of dict1, #contents of dict2, contents of dict3, contents of dict5, contents of dict6}
Essentially I'm trying to unpack the contents of {dict4}, item by item and append it onto the end of the output dictionary so that the final {output} = fully flattened "key":"value" pairs. Some dicts have nested strings, some dicts have nested dicts.
Once that code chunk is done, I have to unpack another group of nested dictionaries but I should be able to extrapolate from here.