Coding style

Donn Cave donn at u.washington.edu
Mon Jul 17 17:16:43 EDT 2006


In article <mailman.8257.1153158306.27775.python-list at python.org>,
 Steve Holden <steve at holdenweb.com> wrote:
> tac-tics wrote:
...
>> I'd say the second one. Empty lists are not false. They are empty.
>> Long live dedicated boolean data types.

> Take them off to where they belong!

Tac-tics is right, an empty list is not False.

Anyway, just for some variety, I think (2) is preferrable
to (1), as is the following

  while 1:
    try:
      lst.pop()
    except IndexError:
       break

Rather than blindly apply familiar patterns to our work,
I think everyone would agree that coding style in matters
like this should follow the underlying point of the code.
In this case, the body of the test refers implicitly to
the length of the list, since .pop() -> (list[a], list[:a])
where a is (len(list) - 1)  It's therefore quite appropriate
for the test to be length.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list