PEP 285: Adding a bool type
Lulu of the Lotus-Eaters
mertz at gnosis.cx
Mon Apr 8 17:27:09 EDT 2002
|the Lotus-Eaters wrote:
|> 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)]))
|from operators impor add
|fs = ...
|major = reduce(add, [f(o) for f in fs])
Well... my version is two bytes shorter :-) (more if you count the extra
import).
The real problem, however, with Magnus' version is that if the functions
return some overloaded true value rather than nice 0/1 booleans, his
doesn't work. I started to try to do a reduce() version, but then felt
like I would have needed a filter() or map() to get cannonical 0/1
values. My len() version handles functions that might return
empty/non-empty lists, other integers, etc.
Yours, Lulu...
--
mertz@ | The specter of free information is haunting the `Net! All the
gnosis | powers of IP- and crypto-tyranny have entered into an unholy
.cx | alliance...ideas have nothing to lose but their chains. Unite
| against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------
More information about the Python-list
mailing list