Open jgmbenoit opened 2 years ago
The suggested solution has a pitfall that somehow reproduces the same issue. If we use the same content to initialize kanga and roo, then a new content put in one of them also appears in the other one. More specifically, if we replace
kanga
roo
kanga = Kangaroo('Kanga') roo = Kangaroo('Roo')
by
prepouch=['red','green','blue'] kanga = Kangaroo('Kanga',precontents) roo = Kangaroo('Roo',precontents)
then the output becomes
Kanga has pouch contents: 'red' 'green' 'blue' 'wallet' 'car keys' <__main__.Kangaroo object at 0x7f2b4c049e20> Roo has pouch contents: 'red' 'green' 'blue' 'wallet' 'car keys' <__main__.Kangaroo object at 0x7f2b4c049e20>
while we may expect
Kanga has pouch contents: 'red' 'green' 'blue' 'wallet' 'car keys' <__main__.Kangaroo object at 0x7f0abfdc4d30> Roo has pouch contents: 'red' 'green' 'blue'
I obtained the last output by assigning a copy of contents:
contents
self.pouch_contents = contents[:]
The suggested solution has a pitfall that somehow reproduces the same issue. If we use the same content to initialize
kanga
androo
, then a new content put in one of them also appears in the other one. More specifically, if we replaceby
then the output becomes
while we may expect
I obtained the last output by assigning a copy of
contents
: