Gizmo
Gizmo

Reputation: 39

how to check if a nested list has had its base values changed

I can't think of a way to check if every value in my nested list has changed from its base number in this case 0, how would I do that?

game_board = [ [0,0,0], [0, 0, 0], [0, 0, 0,] ]

Upvotes: 0

Views: 29

Answers (1)

timgeb
timgeb

Reputation: 78760

In case the nesting level is only one and you want to check whether there are numbers other than zero in your list, you can issue:

>>> any(x for sublist in game_board for x in sublist)
False

Alternatively, with another assumption about the length of the "base list":

>>> base = [0, 0, 0]
>>> any(sublist != base for sublist in game_board)
False

Or with numpy:

>>> np.count_nonzero(game_board) != 0
False

Upvotes: 1

Related Questions