I'm trying to create a program that makes a dictionary with a simple test txt file:
first
second
third
To do this I wrote the following code:
def createDict():
with open("test.txt","r") as file:
index = 0
list = {}
for index in range(linecount()//3):#parse 3 lines each loop
list[next(file)] = [next(file),next(file)]
return list;
I want the dictionary to look like
first: [second, third]
but what happens is
third: [first, second]
I managed to get the desired output with this change:
def createDict():
with open("test.txt","r") as file:
index = 0
list = {}
for index in range(linecount()//3):
line1 = next(file)
line2 = next(file)
line3 = next(file)
list[line1] = [line2,line3]
return list;
Why does the first solution not work?