I am trying to add the dictionary values and keys dynamically.
Example:
First i will have the dictionary as:
dict1 = {'ID':2048, 'Name':'john', 'Father Name':'David'}
Then in the next iteration dictionary should be updated with below:
dict1 = ({'ID':2048, 'Name':'john', 'Father Name':'David'}, {'ID':2054, 'Name':'steve', 'Father Name':'Bird'})
Then the next iteration will be
dict1 = ({'ID':2048, 'Name':'john', 'Father Name':'David'}, {'ID':2054, 'Name':'steve', 'Father Name':'Bird'}, {'ID':2046, 'Name':'Calvin', 'Father Name':'Adam'})
And so on.....
Then i have to sort the dict1 as per the ID as below:
dict1 = ({'ID':2046, 'Name':'Calvin', 'Father Name':'Adam'}, {'ID':2048, 'Name':'john', 'Father Name':'david'}, {'ID':2054, 'Name':'steve', 'Father Name':'Bird'})
I have tried with below code:
dict1 = {}
## Here Candidate_ID, Candidate_Name and Candidate_Father_Name will be updated as per the script flow.
dict1.update({'ID': Candidate_ID, 'Name': Candidate_Name, 'Father Name' : Candidate_Father_Name)
Please suggest how to update the keys in dictionary with same values(ID, Name, Father Name), And then to sort the dictionary with value "ID".
dict1 = ({'ID':2048, 'Name':'john', 'Father Name':'David'}, {'ID':2054, 'Name':'steve', 'Father Name':'Bird'})is not a dictionary but a tuple of dicts. Use a list af dicts to append the dicts in each iteration.