[Tutor] Testing for empty list
davea at ieee.org
Mon Oct 19 10:52:40 CEST 2009
> Hi, I think I recall seeing this here, but I wanted to make sure I'm
> Is the best way to test for an empty list just test for the truth value?
> mylist = [1,2,3]
> while mylist:
> print mylist.pop()
My take is simple: Use the above form if you *know* that mylist is in
fact a list. If you don't know its type for sure (the name is a clue,
but not conclusive ;-) ) then use a more specific test.
In your case, you know it's a list, or least something that supports
pop(). So your form should be great.
More information about the Tutor