[Tutor] Testing for empty list
vince spicer
vinces1979 at gmail.com
Mon Oct 19 03:41:18 CEST 2009
On Sun, Oct 18, 2009 at 7:29 PM, Wayne <srilyk at 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
>
> --
> To be considered stupid and to be told so is more painful than being called
> gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
> every vice, has found its defenders, its rhetoric, its ennoblement and
> exaltation, but stupidity hasn’t. - Primo Levi
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
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()
Vince
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091018/3f417d02/attachment.htm>
More information about the Tutor
mailing list