This is my code for copying data from the old stack to the new stack then enqueue them to the queue
for word in dictionary:
if len(word) == len(lastWord): #Make sure same len
if (oneLetterDiff(word, dequeuedStack.peek())) == True and (word in dequeuedStack._data) == False: #One letter difference
s = MyStack()
print 'before %s' % dequeuedStack._data
s.copyFrom(dequeuedStack) #Copy stack over
s.push(word) #Add new word
print 'after %s' % s._data
q.enqueue(s) #Enqueue the stack
print 'after copying %s' % dequeuedStack._data
print word
This is the code for copying the list
def copyFrom(self, aStack):
self._data = aStack._data
And this is to append it to the queue
def enqueue(self, value):
self._data.append(value)
However, dequeuedStack._data
was changed without me calling any methods to modify it
This is an example of the output
['stone', 'atone']
before ['stone', 'atone']
after ['stone', 'atone', 'alone']
after copying ['stone', 'atone', 'alone']
alone
before ['stone', 'atone', 'alone']
after ['stone', 'atone', 'alone', 'clone']
after copying ['stone', 'atone', 'alone', 'clone']
clone