and [True,True] --> [True, True]?????
tjreedy at udel.edu
Tue Apr 21 02:20:44 CEST 2009
Gerhard Häring wrote:
> Martin v. Löwis wrote:
>>> Are they widespread? I haven't noticed, yet.
>>> I prefer to write it explicitly:
>>> if len(lst) > 0:
>> I prefer to test explicitly for the truth value of the
>> list. I don't want to test whether the length of the list
>> is greater than 0 (in fact, I don't care about the length
>> property of the list at all) - I want to know whether the
>> list is empty (or not empty). The Python syntax for this
>> test is
>> if lst:
>> # not empty
>> if not list:
> You're right - as most of the time ;-) This makes a lot of sense to me.
> The reason I preferred len(), btw., was only that len() make it clear
> that the argument is a sequence.
> Maybe I was just too annoyed by lots of Python code I read that looked
> like this:
> def foo(x, y, z):
> if x:
> with poorly named variables where I didn't know what the heck the
> variables are (bool, list, instance, ...). I hate it when I have to look
> for the actual method calls to figure out what's going in. Better
> variable naming and small comments would often help.
In my view, that is only excusable in throw-away private code or in
languages like early BASIC where only one letter is allowed, and even
then, 'x' should be a number, not a collection.
More information about the Python-list