Re: [Tutor] Empty list validation

2008-06-09 Thread [EMAIL PROTECTED]
Thank you all for the replies. the 'else' is this necessary, surely when you have an: >>> if x: ... print 'x' ...print 'y' is this correct? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Empty list validation

2008-06-09 Thread simone
[EMAIL PROTECTED] ha scritto: Sorry if this is a basic question, but how do I check if list is empty or not and return True or False ;) Normally, in Python, there are these evaluation: 1) True == 1 2) False == 0 3) Empty or have not value == False == 0 4) Not empty or have value == True == 1

Re: [Tutor] Empty list validation

2008-06-09 Thread Kent Johnson
On Mon, Jun 9, 2008 at 10:25 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello > Sorry if this is a basic question, but how do I check if list is empty > or not and return True or False ;) You can test the list directly, if it is empty it will evaluate to False: if (myList): print 'Somet

Re: [Tutor] Empty list validation

2008-06-09 Thread C S Shyam Sundar
One another simple method is to check its count using the *len *method. eg: if len(mylist) == 0: print "empty list" This is particularly useful in situations where checking emptiness alone is not enough. On Mon, Jun 9, 2008 at 8:24 PM, W W <[EMAIL PROTECTED]> wrote: > >>> def empty_or_not

Re: [Tutor] Empty list validation

2008-06-09 Thread W W
>>> def empty_or_not(mylist): ... if mylist: ... print "Not empty" ... elif not mylist: ... print "Empty!" ... >>> empty_or_not([]) Empty! >>> foo = [] >>> empty_or_not(foo) Empty! >>> foo.append('hi') >>> empty_or_not(foo) Not empty My guess is that if any object is empty,

[Tutor] Empty list validation

2008-06-09 Thread [EMAIL PROTECTED]
Hello Sorry if this is a basic question, but how do I check if list is empty or not and return True or False ;) Thanks David ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor