I know this is a rather trivial question, but that's why I thought too when I was trying to solve it. Yet, I am here and asking this question. It should be very easy and probably I am doing something completely wrong, but I'd like to know what I am doing wrong.
I have this list of strings:
['1', ' ', '2', ' ', '6', ' ', '6', ' ', '5', ' ', '6', ' ', '5']
my_list = [str for str in the_list if str]
You don't have empty strings. You have strings with one space in each.
You can remove those by testing if they are empty after stripping:
my_list = [el for el in the_list if el.strip()]
However, you may want to examine how you got that list in the first place. Perhaps you can strip out those spaces earlier, or use
str.split() without an argument to split on arbitrary width whitespace rather than on a fixed-width string.