Re: checking if a list is empty
- From: Raymond Hettinger <python@xxxxxxx>
- Date: Fri, 6 May 2011 15:52:18 -0700 (PDT)
On May 5, 11:36 pm, Jabba Laci <jabba.l...@xxxxxxxxx> wrote:
If I want to check if a list is empty, which is the more pythonic way?
li = 
(1) if len(li) == 0:
(2) if not li:
The Python core developers use the second form.
for the official recommendation.
- Re: while c = f.read(1)
... The problem with interpreting empty as false is that empty ... > If Python is too "wild" for your taste, ... In that case you wouldn't return an empty sequence if you wanted ... a false value in a sequence context but would throw an exception. ...
- Ply(LALR) and Yacc behaving differently
... I am trying to implement a small compiler in python and, ... Perhaps this belongs on some compiler list, but I couldn't decide if it ... Empty ... def p_Block: ...
- Re: How is the logical processing being done for strings like Dog and Cat
... All Python objects have a boolean context. ... Python's boolean operators are short-circuit operators. ... As a general rule, false values are empty: ...
- Re: chop() and empty() functions
... empty, no-op function of some sort when you want to at least have ... If you intend to set explicit handlers later, wouldn't it be better for the default event handler to raise an exception, just in case your intention is waylaid or sidetracked? ... happening (although, this could currently be the case in Python, I'm not ... Python will not assume that you meant to supply a no-op function. ...
- Re: Boolean tests [was Re: Attack a sacred Python Cow]
... patronizing me ... You suggested a syntax for testing non-emptiness (`x is not empty`) ... some idiot did just that almost immediately. ... Python, you are simply wrong. ...