Hi all,
I have a Ring structure implemented as follows (based on a cookbook recipe I found):
class Ring(list):
def turn(self):
last = self.pop(0)
self.append(last)
def setTop(self, objectReference):
if objectReference not in self:
raise ValueError, "object is not in ring"
while self[0] is not objectReference:
self.turn()
Say I do the following:
x = Ring([1,2,3,4,4])
x.setTop(4)
My code will always set the first 4 (currently x[3]) to x[0]. It seems (via object identity and hash id testing between x[3] and x[4]) that Python is reusing the 4 object.
How do I tell Python that I really want the second 4 (currently x[4]) to be at the top?
Apologies for the basic question ... one of the downfalls of being a self-taught beginner.
Thanks,
Mike
===EDIT===
For what it's worth, I dropped the setTop method from the class. I had added it to the standard recipe thinking "hey, this would be neat and might be useful." As the answers (esp. "what's the difference", which is spot on) and my own experience using the structure show, it's a crappy method that doesn't support any of my use cases.
In other words, adding something because I could instead of fulfilling a need = fail.