so 'inand 'forstop def __repr__(self)return '[faststack:repr(self stack']this class' __getitem__ method handles indexingin testsand for loop iteration as before (when no __iter__ is defined)but this version has to traverse tree to find node by index notice that this isn' subclass of the original stack class since nearly every operation is implemented differently hereinheritance won' really help but clients that restrict themselves to the operations that are common to both classes can still use them interchangeably--they just need to import stack class from different module to switch implementations here' session with this stack versionas long as we stick to pushingpoppingindexingand iteratingthis version is essentially indistinguishable from the originalfrom stack import stack stack( stack(for in 'spam' push(cfor in range( ) push(ix [faststack:(' '(' '(' '(' 'none)))) [faststack:( ( ( none)))len( ) [ ] [- ( ' '' ' pop('mx [faststack:(' '(' '(' 'none)))while yprint( pop()end=' optimizationin-place list modifications the last section tried to speed up pushes and pops with different data structurebut we might also be able to speed up our stack object by falling back on the mutability of python' list object because lists can be changed in placethey can be modified more quickly than any of the prior examples in-place change operations such as append are prone to complications when list is referenced from more than one place but because the list inside the stack object isn' meant to be used directlywe're probably safe the module in example - shows one way to implement stack with in-place changessome operator overloading methods have been dropped to keep this simple the python pop method it uses is equivalent to indexing and deleting the item at implementing stacks