Skip to content
Advertisement

Python Check if at least 1 item in a 2d list is None

Consider some 2d lists:

JavaScript

How to check if there is at least one None in a 2d list?

Outputs: deal with a should output a bool value False, and b should output True.

I have no ideas when the list be a 2d list.

Advertisement

Answer

You can use two loops, one inside the other.

JavaScript

This can be simplified by using None in row rather than the inner loop.

JavaScript

Either could be written using any() with a generator expression:

JavaScript

And at that point you barely need the function.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement