i know this is a noob question but im an new learner to Python and im struggling with dictionary's.
i think my code is right but im not sure.
what i am trying to achieve is that i want to iterate trough a dictionary with a list items with a dictionary in it. If the value is == None then that key Should be skipped. but if there is a value. i want to append the Key:Value pair to the pmp_dict = {}
here is my code:
input_dict = {
"operation": {
"Details": {
"ACCOUNTLIST": {
"RESOURCENAME": "abbas",
"ACCOUNTNAME": "account_name",
"RESOURCETYPE":None,
"PASSWORD": "password"
}
}
}
}
pmp_dict= {
"operation": {
"Details": {
"ACCOUNTLIST": [
{
}
]
}
}
}
print(pmp_dict)
for list_item in input_dict["operation"]["Details"]["ACCOUNTLIST"]:
for key, value in list_item.items():
if value == None:
pass
else:
pmp_dict["operation"]["Details"]["ACCOUNTLIST"][key]=value
what Im struggling with is the last 5 lines. how do i write so that i achieve the desired outcome? i know what i want to do but not the syntax for it.
when i do this i get error:
Traceback (most recent call last):
File "<string>", line 29, in <module>
AttributeError: 'str' object has no attribute 'items'