Skip to content Skip to sidebar Skip to footer

Python List Of Dictionaries Only See Last Element

Struggling to figure out why this doesn't work. It should. But when I create a list of dictionaries and then look through that list, I only ever see the final entry from the list:

Solution 1:

You create exactly one dict at the beginning of the script, and then append that one dict to the list multiple times.

Try creating multiple individual dicts, by moving the initialization to the inside of the loop.

alerts = []
af=open("C:\snort.txt")

for line in af:
    alertDict = {}
    #rest of loop goes here

Post a Comment for "Python List Of Dictionaries Only See Last Element"