tuples, index method, Python's design

BJörn Lindqvist bjourne at gmail.com
Tue Apr 10 11:10:07 EDT 2007


On 4/10/07, Carsten Haese <carsten at uniqsys.com> wrote:
> i = p.index(current_player)
> opponents = p[:i-1] + p[i+1:]
>
> An alternative is this:
>
> opponents = tuple(x for x in p if x is not current_player)
>
> You may disagree, but in my opinion, the alternative is better because
> it is a more natural translation of the concept that the opponents of
> the current player are all players that are not the current player.

Your alternative is wrong because it wont raise ValueError if
current_player is not present in the tuple. Please revise your
"solution."


-- 
mvh Björn



More information about the Python-list mailing list