"Katt" wrote
Just a newbie question, but when would you test for an empty list?
When you are processing a list such that you are deleting items as you go.
When the list is empty stop processing!
And Python helps you do that by treating an empty list as a False
boolean value so you can do
2009/10/19 Katt
>
> Hello all,
>
> Just a newbie question, but when would you test for an empty list? Is it
> part of a code error detection or an error check to make sure that there is
> user input?
>
> Couldn't you just use something like:
>
> while len(mylist) > 0:
> continue program
> els
Wayne 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
My take is simple: Use the above form if you *know* th
Hi,
please don't top-post.
Todd Matsumoto wrote:
> I don't understand how the while loop efficiently tests if the list is
> empty.
It doesn't. It only tests a condition. And the result of the condition is
determined by the list itself, which knows if it's empty or not.
Stefan
- Original-Nachricht
> Datum: Mon, 19 Oct 2009 04:52:40 -0400
> Von: Dave Angel
> An: Wayne
> CC: "tutor@python.org"
> Betreff: Re: [Tutor] Testing for empty list
>
>
> Wayne wrote:
> > Hi, I think I recall seeing this here, but I wanted to make sur
Wayne 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
My take is simple: Use the above form if you *know*
On Mon, Oct 19, 2009 at 2:26 AM, Todd Matsumoto wrote:
> The while loop will print each index of the list.
No it's printing each element of the list, not the index.
> In a way it checks that if the list is empty by printing the items. As far
> as I know there isn't any 'True' or 'False' output
"Todd Matsumoto" wrote
The while loop will print each index of the list.
No, the while does nothing with list indexes, that is entirely
down to the programmer. The while loop simply repeats for
as long as its test expression evaluates to True.
As far as I know there isn't any 'True' or 'Fal
On Mon, Oct 19, 2009 at 3:29 AM, Wayne 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
if not mylist:
... do something ...
T
Original-Nachricht
> Datum: Sun, 18 Oct 2009 20:29:53 -0500
> Von: Wayne
> An: "tutor@python.org"
> Betreff: [Tutor] Testing for empty list
> Hi, I think I recall seeing this here, but I wanted to make sure I'm
On 19-Oct-09, at 7:11 AM, vince spicer wrote:
On Sun, Oct 18, 2009 at 7:29 PM, Wayne 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:
p
On Sun, Oct 18, 2009 at 7:29 PM, Wayne 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
>
>
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
13 matches
Mail list logo