+ 2

Challenge question

Here is code from a challenge question. The answer is 10, but I need some help with the reasoning. List1 is passed to the guess function, then list2 is a copy of list1, then appends 4 to the end of list2 which in turn appends it to the end of list1. I thought everything was fine until the assignment to list1. How does that not change the value of list1 before the print statment? https://code.sololearn.com/c3OfxnSLGJIq/?ref=app

25th Aug 2020, 12:25 PM
GeoK68
GeoK68 - avatar
2 Answers
+ 1
Run the code and check, if you still can't understand then let us know. https://code.sololearn.com/cp917ZSBHD3N/?ref=app
25th Aug 2020, 12:36 PM
minirkk
minirkk - avatar
+ 1
So the new assignment for list1 references a different memory location.
25th Aug 2020, 3:21 PM
GeoK68
GeoK68 - avatar