My list is like this,
mylist=[ " ","abc","bgt","llko"," ","hhyt"," "," ","iuyt"]
How to remove all spaces containing strings inside this list?
You could use a list comprehension:
new_list = [elem for elem in mylist if elem.strip()]
Using strip()
guarantees that even strings containing only multiple spaces will be removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With