i have a list that contains a few dictionaries. I want to extract the dictionaries from this list and add them to a new dictionary.
testList = [{"Name":"Jim"},{"Age":"25"},{"Location":"UK"}]
however, i can't quite get it to work. so far, I've tried a simple for loop to sift through the list and update it to a new target accordingly, if the entries found in it happen to be a dictionary:
for dictionary in testList:
if dictionary is dict:
for k, v in dictionary.items():
newDict = {}
newDict.update(k,v)
i managed to get it working, but it seemingly only updated the last dictionary entry in the list and not just add them all to it when i was experimenting with earlier code. I also tried to take a copy of it calling the '.copy()' method but that had no luck either. Now the newDict, when i print it, is empty still! anyone know what i'm doing wrong? i'd appreciate any help here because i have a feeling i'm not too far off! i can print the length of the list and see it has 3 items, which is expected. So i'm not sure why when i had it partially working before that it only lifted the last dictionary only.