Example:
Column 1
[1, 3, " "]
[2, " ", 3]
etc.
Is there a quick list compehension where I can keep just the integers?
Example:
Column 1
[1, 3, " "]
[2, " ", 3]
etc.
Is there a quick list compehension where I can keep just the integers?
You are probably looking for something like so:
a = [1, 3, " "]
b = [i for i in a if i != " "]
print(b) #> [1, 3]
If you want to include other spaces to remove:
a = [1, 3, " ", ""]
b = [i for i in a if i not in (" ", "")]
If you want to only add int
(if there are str
, float
, etc. this method will not generalize):
a = [1, 3, " ", ""]
b = [i for i in a if isinstance(i, int)]