tuples, index method, Python's design

Carsten Haese carsten at uniqsys.com
Wed Apr 11 01:06:24 EDT 2007


On Tue, 2007-04-10 at 21:23 -0700, Paul Rubin wrote:
> Carsten Haese <carsten at uniqsys.com> writes:
> > You have a point. Here is my revised solution:
> > 
> > assert current_player in p
> > opponents = tuple(x for x in p if x is not current_player)
> 
> Still wrong on two counts.  First, assert is a no-op if optimization
> is turned on.

Right. I already responded to this when Bjorn made the same objection.
Please try to keep up.

>   Second, your version returns a different result from
> the original if current_player occurs in p more than once.

First of all, in the use case we're talking about, current_player
shouldn't occur in p more than once. And if it did, is it really
reasonable to demand that that player be their own opponent? I don't
think so. So yes, the result is different because it's correct, and the
tuple.index-based solution is actually incorrect in this case.

-Carsten





More information about the Python-list mailing list