Re: Coding style



In article <mailman.8257.1153158306.27775.python-list@xxxxxxxxxx>,
Steve Holden <steve@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxx
.



Relevant Pages

  • Re: Coding style
    ... Empty lists are not false. ... live dedicated boolean data types. ...
    (comp.lang.python)
  • Re: Coding style
    ... tac-tics wrote: ... live dedicated boolean data types. ...
    (comp.lang.python)
  • Re: Coding style
    ... Empty lists are not false. ... live dedicated boolean data types. ...
    (comp.lang.python)
  • Re: Coding style
    ... Empty lists are not false. ... live dedicated boolean data types. ...
    (comp.lang.python)