I need to update a single nested dictionary at once.
I have a for loop where rows is a NodeList (minidom)
Where dictKeys looks like this :
dictKeys = {'LastEditDate': {}, 'LastEditorUserId': {}, 'LastActivityDate': {}, 'Id': {}, 'CommentCount': {}, 'ParentId': {}, 'CreationDate': {}, 'Title': {}, 'PostTypeId': {}, 'AnswerCount': {}, 'ClosedDate': {}, 'OwnerUserId': {}, 'ViewCount': {}, 'Body': {}, 'Score': {}, 'AcceptedAnswerId': {}, 'OwnerDisplayName': {}, 'Tags': {}, 'FavoriteCount': {}}
for index,element in enumerate(rows):
for key in dictKeys.keys():
dictKeys[key][index] = ""
for attrName, attrValue in element.attributes.items():
dictKeys[attrName][index]= attrValue
Instead of each key value pair updating on each iteration, they're all updating at once.
{'LastEditDate': {0: '11062'}, 'LastEditorUserId': {0: '11062'}, 'LastActivityDate': {0: '11062'}, 'Id': {0: '11062'}, 'CommentCount': {0: '11062'}, 'ParentId': {0: '11062'}, 'CreationDate': {0: '11062'}, 'Title': {0: '11062'}, 'PostTypeId': {0: '11062'}, 'AnswerCount': {0: '11062'}, 'ClosedDate': {0: '11062'}, 'OwnerUserId': {0: '11062'}, 'ViewCount': {0: '11062'}, 'Body': {0: '11062'}, 'Score': {0: '11062'}, 'AcceptedAnswerId': {0: '11062'}, 'OwnerDisplayName': {0: '11062'}, 'Tags': {0: '11062'}, 'FavoriteCount': {0: '11062'}}
and
{'LastEditDate': {0: '2'}, 'LastEditorUserId': {0: '2'}, 'LastActivityDate': {0: '2'}, 'Id': {0: '2'}, 'CommentCount': {0: '2'}, 'ParentId': {0: '2'}, 'CreationDate': {0: '2'}, 'Title': {0: '2'}, 'PostTypeId': {0: '2'}, 'AnswerCount': {0: '2'}, 'ClosedDate': {0: '2'}, 'OwnerUserId': {0: '2'}, 'ViewCount': {0: '2'}, 'Body': {0: '2'}, 'Score': {0: '2'}, 'AcceptedAnswerId': {0: '2'}, 'OwnerDisplayName': {0: '2'}, 'Tags': {0: '2'}, 'FavoriteCount': {0: '2'}}
I am wondering how to do this properly?