Coding style

dwelch91 donald.welch at hp.com
Mon Jul 17 12:15:22 EDT 2006


PTY wrote:
> Which is better?
> 
> lst = [1,2,3,4,5]
> 
> while lst:
>   lst.pop()
> 
> OR
> 
> while len(lst) > 0:
>   lst.pop()
> 

I think the first one is better, but if all you are doing is removing 
all the items in the list, this is definitely better:

lst = []

-Don



More information about the Python-list mailing list