I have a string that consist of characters which all of them divided by comma and I want to create a list with the integers only. I wrote:
str = '-4,, 5, 170.5,4,s, k4, 4k, 1.3, ,, 8'.replace(' ','')
# Now the str without spaces: '-4,,5,170.5,4,s,k4,4k,1.3,,,8'
lst_str = [item for item in str.split(',')
# Now I have a list with the all items: ['-4', '5', '170.5', '4' ,'s', 'k4' ,'4k', '1.3', '8']
int_str = [num for num in lst_str if num.isdigit]
# The problem is with negative character and strings like '4k'
# and 'k4' which I don't want, and my code doesn't work with them.
#I want this: ['-4', '5', '4', '8'] which I can changed after any item to type int.
Can someone help me how to do that? Without importing any class. I didn't find an answer for this specific question (its my first question)