Question
I made a for loop reading the contents of the list, however, assigning two values ββto the dictionary, and then adding this output to the list, the next value overwrites everything in the list
Desired Result
I want to add several dictionaries to the list, so when I run the for loop and print everything connected with "ip", it will print all the values ββassociated with the value of the dictionary "ip".
code
device = { 'ip': '', 'mac': '', 'username': 'admin', 'password': [], 'device type': '', } listofdevices = [] def begin(): file = open("outputfromterminal") contents = file.read() contents = contents.split(',')[1:] for x in contents:
Code example
1st content index:
x[0] = '10.10.10.1' x[1] = 'aa:bb:cc:dd'
Second content index:
x[0] = '20.20.20.1' x[1] = 'qq:ww:ee:ee:rr'
What is really going on
listofdevices[0] 'ip': 20.20.20.1, 'mac': 'qq:ww:ee:ee:rr' listofdevices[1] 'ip': 20.20.20.1, 'mac': 'qq:ww:ee:ee:rr'
source share