-5

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

2 Answers2

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

The above code works because empty strings - ie '' - evaluate to False.

spencer.pinegar
  • 442
  • 2
  • 10
0

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

or

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

William
  • 16
  • 1