Oct-30-2017, 08:46 AM
So,
txt = open('testfile.txt','r') d= {} numLines = 0 #reading = txt.readlines() read = txt.readline() print(read) for line in txt.readlines(): numLines += 1 #print(numLines) if numLines not in d: d[numLines] = [txt.readline()] print(d)It's giving me the following:
Output:{1: [''], 2: [''], 3: ['']}
I actually want it to count the number of lines, and for example, in line number 1, I want the values of the dictionary to have the contents of the file split into a list.