I have a problem. I would like to convert a list of strings with 594 elements, among them many empty, to a list of integers. I already looked up many answers here, but neither list comprehensions, neither map function seems to work. My command prompt simply says int argument must be a string or a number, not a list.
Here is my code:
fname = raw_input("Enter file name: ")
if len(fname) < 1 : fname = "regex_sum_317625.txt"
fh = open(fname)
import re
numlist = list()
for line in fh:
line = line.rstrip()
numbers = re.findall('[0-9]+', line)
numlist.append(numbers)
print numlist
listlength = len(numlist)
print listlength
intlist = [int(nums) for nums in numlist]
print intlist
I tried many ways, but the problem always is that I try to do an operation on a list which is not allowed. Could you please help me, what should I do?