0

I have the following Python list:

a = [2, 3, 4, False, 10, 1, False, 20]

I would like to know which pythonic way would be used to replace all Falses with ''. I have tried to find a .replace method but can not find something applicable to all items (as it happens in Pandas).

Python 2.7

M.E.
  • 4,955
  • 4
  • 49
  • 128

1 Answers1

1
    a = [2, 3, 4, False, 10, 1, False, 20]
    a = [each if each != False else '' for each in a];
    print(a)

Check out this article. I got this to work in an online python compiler. I literally just saw Peter's answer after I posted. Rip me.

Shmack
  • 1,933
  • 2
  • 18
  • 23