Reputation: 71
I have a specific file that I extracted lines from and it had a lot of space in it after put these lines in a list
lines_list = open('data\wonderland.txt').read().splitlines()
I end up with this result
[' Down the Rabbit-Hole','','','','Alice was beginning to get very tired of sitting by her sister on the','','bank, and of having nothing to do: once or twice she had peeped into the','',
I specifically want to delete the ''
from my list
Upvotes: 0
Views: 63
Reputation: 2732
Use the built-in filter
function:
lines_list = list(filter(None, lines_list))
Output:
[' Down the Rabbit-Hole', 'Alice was beginning to get very tired of sitting by her sister on the', 'bank, and of having nothing to do: once or twice she had peeped into the']
Or just:
lines_list = [i for i in lines_list if i]
Which has the same output
Upvotes: 4