+ 2
Problem with append
https://code.sololearn.com/c30smJbp4vz3/?ref=app In this code I'm trying to get a list of all ternary numbers (base 3) with a certain length that is passed to the function. When I print the combination I get the right result But when I append them onto a list and return it all combinations (of 0, 1, 2) are all '2'
4 Réponses
+ 1
Does changing lines 10 and 23 to result.append(arr[:]) fix your issue?
When you directly append arr to result, whatever changes you make to arr get reflected in result as well. Your last value of arr is ['2', '2'], so result only has that list repeated a number of times.
When you do result.append(arr[:]), you are actually appending a (shallow) copy of arr, not the list arr itself. That's why this should do work for your problem.
Does that make sense?
+ 1
it makes sense thank, you!!
+ 1
Great! You're most welcome, Anton!
Happy coding! 😊
0
how can i do a is_palindrome_ stack ( text) function with the stack method ?🤔