input - How to remove empty separators from read files in Python? -


here input file sample (z.txt)

>qrst abcde--  6  6 35 25 10 >qqqq abbde--  7  7 28 29  2 

i store alpha , numeric in separate lists. here output of numerics list #output : ['', '6', '', '6', '35', '25', '10'] ['', '7', '', '7', '28', '29', '', '2']

the output has space when there single digits because of way file has been created. there anyway rid of '' (empty spaces)?

you can take advantage of filter none function that:

numbers = ['', '7', '', '7', '28', '29', '', '2'] numbers = filter(none, numbers) print numbers 

see in action here: https://eval.in/640707


Comments

Popular posts from this blog

php - Auto increment employee ID -

python - Evaluating the next line in a For Loop while in the current iteration -

php - Facebook share link is not showing image within the post?(get parameter in url) -