any() and all() on empty list?

Peter Otten __peter__ at
Thu Mar 30 11:35:40 CEST 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

- You have one valuable and one piece of lesser value threatened. You play

What is that? The courage of despair?

if any(piece.value > 5 for piece in threatened):
    # play cautiously
    # play daringly

looks more convincing to the non-chessplaying bystander (read: me) and --
surprise -- is supported by the new builtins just fine.


More information about the Python-list mailing list