Coding style
Steve Holden
steve at holdenweb.com
Mon Jul 17 12:12:28 EDT 2006
PTY wrote:
> Which is better?
>
> lst = [1,2,3,4,5]
>
> while lst:
> lst.pop()
>
> OR
>
> while len(lst) > 0:
> lst.pop()
>
The former, without a doubt. It says exactly the same thing, since lst
can only be considered false when it is empty. Experienced Python
programmers would scratch their heads at your second formulation.
I doubt there's much in it from a time point of view (though I know as I
write this it will spur someone to use timeit.py to point out I am wrong).
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list