How to know that the list is empty? In some cases, this approach
if len(lst) == 0: return 1 may cause an error. How to do it right?
How to know that the list is empty? In some cases, this approach
if len(lst) == 0: return 1 may cause an error. How to do it right?
Unlike some programming languages, in Python an object is considered false only if it is empty. This means that you do not need to check the length of a string, tuple, or dictionary — it suffices to check it as a logical expression.
Taken from here , you can find something else useful.
Therefore, the @Vladimir Gamalian version proposed in the commentary is appropriate:
if not lst: Source: https://ru.stackoverflow.com/questions/524081/
All Articles
if not lst:not suitable? - Vladimir Gamalyandef len(a): return 1? - Vladimir Gamalyanfilenames for their variables is quite common. - Vladimir Gamalyan