On 19-Oct-09, at 7:11 AM, vince spicer wrote:



On Sun, Oct 18, 2009 at 7:29 PM, Wayne <sri...@gmail.com> wrote:
Hi, I think I recall seeing this here, but I wanted to make sure I'm correct.

Is the best way to test for an empty list just test for the truth value? I.e.

mylist = [1,2,3]

while mylist:
   print mylist.pop()

Thanks,
Wayne


I believe it is better to check the list length, I think some changes are coming on evaling list


mylist = [1,2,3]

while len(mylist) > 0:
   print mylist.pop()

or
<code>
while mylist != []:
    print mylist.pop()
</code>

or for reverse iteration without popping the values in the list.

<code>
for x in reversed(mylist):
    print x
</code>

regards,
shantanoo
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to