The not any() Function
00:00
In this lesson you’ll cover the none() function—or that is, the lack of none() function, because there is no none() function in Python. That said, you can easily recreate what a none() function would be by using not any().
00:15
So say you had the example again of cases_per_thousand. That is a list of numbers. The question you’re interested in asking now is whether there are any places that have cases over five hundred.
00:26
And the context for this question is that you want to know if it’s safe enough for a certain event to happen in this city. You could use any() with a list comprehension as you’ve done before.
00:37
So cases for cases in cases,
00:45
and the condition is > 500, and this will return False, but perhaps for semantic reasons, for reasons for clarity within your program, you want this value to be True.
01:01
All you need to do in that case is put a not before that. So it will just flip any values. So this is equivalent to what you might imagine a none() function to be: basically, if there are no values that are True, then it will return True.
01:19
And that’s it. There is no none() function, but you can use not any(). Next up, you’re going to be looking a bit closer at Boolean evaluation and how any() can deal with values that aren’t explicitly True or False.
Become a Member to join the conversation.
