Generating a list of None
Bengt Richter
bokr at oz.net
Fri Jul 15 19:24:52 EDT 2005
On 14 Jul 2005 19:25:41 -0700, "Nicolas Couture" <nicolas.couture at gmail.com> wrote:
>Hi,
>
>Is it possible to generate a list of `None' ?
>
>opts.__dict__.values() below could be represented by [None, None, None]
>
>---
>def get_options(opts):
> """Return True or False if an option is set or not"""
> vals = opts.__dict__.values()
>
> for val in vals:
> if val is not None:
> return True
>
> return False
>---
>
>This is how I'd like to see it:
>
>---
>def get_options(opts):
> """Return True or False if an option is set or not"""
> vals = opts.__dict__.values()
>
> for if vals is [None * len(vals)]:
> return False
>
> return True
>---
how about (untested)
def get_options(opts):
"""Return True or False if an option is set or not"""
return [1 for val in vars(opts).values() if val is not None] and True or False
Regards,
Bengt Richter
More information about the Python-list
mailing list