I have a file containing numerical values:
1
4
6
10
12
and I'm trying to append these values into its respective position in an array where i would obtain:
[None,1,None,None,4,None,6,None,None,None,10,None,None,12]
Since 1 from the file would be at index 1 in the list, 4 from the file would be at index 4 in the list and so on.
I begin by first reading in the file:
filename = open("numbers.txt", "r", encoding = "utf-8")
numfile = filename
lst = [None] * 12
for line in numfile:
line = line.strip() #strip new line
line = int(line) #making the values in integer form
vlist.append(line) #was thinking of line[val] where value is the number itself.
print(vlist)
but I'm getting the output:
[None,None,None,None,None,None,None,None,None,1,4,6,10,12]
Where the numbers are appended to the far right of the array. Would appreciate some help on this.