0

Python code problem

I only changed the value of list "b" but list "a" is also changed. Please have a look at my code. https://code.sololearn.com/cGVTfZ2K2xZC/?ref=app

31st Jul 2021, 4:13 PM
Gajendra Sonare
Gajendra Sonare - avatar
4 Respuestas
+ 5
because b is just a reference to a. they have the same id https://code.sololearn.com/cfKSp5iu9iPX/?ref=app try: Gajendra Sonare b = list(a) # instead of b = a
31st Jul 2021, 4:22 PM
Slick
Slick - avatar
+ 2
Slick Got it!😄
31st Jul 2021, 4:26 PM
Gajendra Sonare
Gajendra Sonare - avatar
+ 2
Wanna get same but independent list? l = [1,2,3,4] l2=l.copy()
31st Jul 2021, 6:50 PM
Shadoff
Shadoff - avatar
- 1
س
1st Aug 2021, 4:36 AM
علی دارزاده