Generating a list of None
Raymond Hettinger
python at rcn.com
Sat Jul 16 05:31:28 EDT 2005
[Bengt Richter]
> 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
While we're tossing around hacks and coding atrocities, we should note
that:
not not x
outperforms:
x and True or False
neither of which is as clear as:
bool(x)
Raymond
More information about the Python-list
mailing list