PEP 285: Adding a bool type
Ralph Corderoy
ralph at inputplus.demon.co.uk
Mon Apr 8 06:57:05 EDT 2002
Hi Lulu,
> > To calculate the major sort key you might do
> > major = can_be_moved(o) + can_be_sized(o) + can_be_stacked(o) +
> > can_be_coloured(o) + can_be_hidden(o)
>
> Of course, I'm sure I'll be justly condmened for preferring:
>
> fs = (can_be_moved, can_be_sized, can_be_stacked,
> can_be_coloured, can_be_hidden)
> major = len([1 for f in fs if f(o)]))
>
> to either :-).
I think you would be if all of fs are known to return 0 or 1 since the
list comprehension is less clear IMHO. There's a lot more going on for
the reader to take in.
Ralph.
More information about the Python-list
mailing list