[Tutor] Testing for empty list

Andre Engels andreengels at gmail.com
Mon Oct 19 09:36:17 CEST 2009

On Mon, Oct 19, 2009 at 3:29 AM, 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()

Whether it is the 'best' way depends on what you mean by 'best', but I
do think it's the most idiomatically pythonic one.

André Engels, andreengels at gmail.com

More information about the Tutor mailing list