any() and all() on empty list?
Peter Otten
__peter__ at web.de
Thu Mar 30 04:35:40 EST 2006
Steven D'Aprano wrote:
> Okay, Ron's example wasn't the best. How about this
> one, from chess:
>
> The intention is to play cautiously if all threatened
> pieces are valuable, and daringly otherwise.
Isn't that example even worse? Compare:
- You have one of your valuable pieces threatened. You decide to play
cautiously.
- You have one valuable and one piece of lesser value threatened. You play
daringly.
What is that? The courage of despair?
if any(piece.value > 5 for piece in threatened):
# play cautiously
else:
# play daringly
looks more convincing to the non-chessplaying bystander (read: me) and --
surprise -- is supported by the new builtins just fine.
Peter
More information about the Python-list
mailing list