I wanted to remove the spaces from my list element and separate them into different list elements. For example, if I have the list:
['Hello world', 'testing', 'testing two']
I'd want the list to look like:
['Hello', 'world', 'testing', 'testing', 'two']
The issue I'm having is that i am reading from a file and I already stripped the newline characters and when I tried to strip the spaces, it doesn't seem to work. Below is my code:
with open(fname, 'r') as f:
words = [line.strip().strip(' ') for line in f]
print words
This just prints out what I mentioned previously above, with the list elements still having spaces.
If anyone could help me out, that'd be great! Thanks!