I want to create an array of numbers out of every line of a text file, The file contains numbers as follow:
11
9
7
12
This is the code i have to open the file and append the numbers to the array:
f = open('randomNumberx.txt','r')
myList = []
for line in f:
myList.append(line.strip())
the code above gives me the following:
['11', '9', '7', '12' ]
and id like to have it as:
[11,9,7, 12]
i am using this for a sorting algorithm and when i have the numbers with the '' it makes my algorithm fail and if i use the array of numbers it works fine. any ideas?
int:myList.append(int(line))'2'> '100'isTrue, that's why sort returns unexpected output.with open('randomNumberx.txt') as f: myList = map(int, f)