Skip to content
Advertisement

How to remove str. Of spaces from list [closed]

A = [“a”,”b”,” “,”c”,” “,”d”] How can I remove str. Of white spaces from this list 🤔

Advertisement

Answer

A = [s for s in A if s.strip() != ”]

or

A = [s for s in A if len(s.strip()) > 0]

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement