[Tutor] Methods that return instances of their own class?

David Perlman dperlman at wisc.edu
Thu Oct 15 20:16:35 CEST 2009

Maybe there's a prettier way to do this, but I did it explicitly like  
this because the "transpose" I needed was specific to the structure of  
the game payoff matrix; it isn't a normal mathematical transpose.  I  
agree that it's hard to read but I'm not sure the specific needs of  
this application allow a cleaner solution.  I'd love to hear it if  
there was one though!

On Oct 15, 2009, at 12:33 PM, Che M wrote:

> > def transpose(self):
> >
> > And that's where I'm at. How can I have the transpose method return
> > another Payoffs object? Here's the beginning of it:
> >
> > def transpose(self):
> > trans=[[(self[0][0][1],self[0][0][0]), (self[1][0][1],self[1]
> > [0][0])],
> > [(self[0][1][1],self[0][1][0]), (self[1][1][1],self[1]
> > [1][0])]]
> Did this have to be hardcoded like this, or is there a more
> Pythonic way to transpose the payoff list?  Maybe it needs
> to look like this, but this does not strike me as very readable.

Unfortunately, as soon as they graduate, our people return
to a world driven by a tool that is the antithesis of thinking:
PowerPoint. Make no mistake, PowerPoint is not a neutral tool —
it is actively hostile to thoughtful decision-making. It has
fundamentally changed our culture by altering the expectations
of who makes decisions, what decisions they make and how
they make them.  -Colonel T. X. Hammes, USMC

More information about the Tutor mailing list