checking if a list is empty
Steven Howe
howe.steven at gmail.com
Wed May 11 18:09:51 EDT 2011
On 05/11/2011 02:47 PM, Steven D'Aprano wrote:
> On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote:
>
>> One principle of object oriented programming is to bestow the objects
>> with properties reflecting known properties from the domain being
>> modelled. Lists do not have truth values in the application domain
> Yes they do. Empty lists are nothing, ergo false, and non-empty lists are
> something, ergo true.
>
>
> >>> a=[]
> >>> if a:
> ... print 'Yes'
> ...
> >>> a=[1]
> >>> if a:
> ... print 'Yes'
> ...
> Yes
Cool; I'd never of thought to try that method to determine if a list was
empty. I usually test it's length.
This looks faster.
More information about the Python-list
mailing list