Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the recommended way to return a boolean for a collection being non-empty in python?

I came across the question Python: What is the best way to check if a list is empty? on SO.

Now if I wanted to return a True (False) depending on whether a collection coll is non-empty (empty) from a function, what's the recommended way of doing this ? return not not coll ?

like image 468
Andre Holzner Avatar asked Dec 17 '22 21:12

Andre Holzner


1 Answers

You could use

return bool(coll)
like image 90
Steef Avatar answered Feb 23 '23 01:02

Steef