Re: Coding style



PTY wrote:
Which is better?

lst = [1,2,3,4,5]

while lst:
lst.pop()

OR

while len(lst) > 0:
lst.pop()

A dozen posts, but nobody has posted the right
answer yet, so I will :-)

It doesn't matter -- use whichever you prefer (*)
This is an angels on the head of a pin issue.

(*) -- If your code is part of an existing body of
code that uses one or the other style consistently,
then you should do the same.

.



Relevant Pages

  • Re: Coding style
    ... while lst: ... A dozen posts, but nobody has posted the right ... non-computer language): ...
    (comp.lang.python)
  • Re: Beyond CL?
    ... > (defun dec-list (lst) ... > Heh, one of the features in my new language is complicated to implement ... Nobody can fix the economy. ...
    (comp.lang.lisp)
  • Re: Coding style
    ... while lst: ... but nobody has posted the right ... It looks like there are two crowds, terse and verbose. ...
    (comp.lang.python)
  • Re: Coding style
    ... PTY wrote: ... while lst: ... Skype: holdenweb http://holdenweb.blogspot.com ... Recent Ramblings http://del.icio.us/steve.holden ...
    (comp.lang.python)