I have a grid (6 rows, 5 columns):
grid = [
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
]
I augment the grid and it might turn into something like:
grid = [
[{"some" : "thing"}, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, {"something" : "else"}, None],
[None, {"another" : "thing"}, None, None, None],
[None, None, None, None, None],
]
I want to remove entire rows and columns that have all None
s in them. So in the previous code, grid would be transformed into:
grid = [
[{"some" : "thing"}, None, None],
[None, None, {"something" : "else"}],
[None, {"another" : "thing"}, None],
]
I removed row 1, 2, 5 (zero indexed) and column 2 and 4.
The way I am deleting the rows now:
for row in range(6):
if grid[row] == [None, None, None, None, None]:
del grid[row]
I don't have a decent way of deleting None
columns yet. Is there a "pythonic" way of doing this?