Reinitializing variable in a while loop
Hello I solved a problem on codewar https://www.codewars.com/kata/5550d638a99ddb113e0000a2 I did it without using the pop function due to optimization concern (having my code time out happened several time). But when I solved it, I saw that the best practice solution used append/pop combination. def josephus2(xs, k): i, ys = 0, [] while len(xs) > 0: i = (i + k - 1) % len(xs) ys.append(xs.pop(i)) return ys I decided to time this solution against mine to see if I was more efficient. Only trouble at the end of each solutions the initial list have been modified. For the best solution it is empty (so of course the subsequent running were super fast) and for mine it contain strings (meaning the code never stop running). So I have to reinitialize the initial value. And for the best practice solution I am not able to do it. Before the while loop I put : v= tuple(xs) but impossible to put a xs = list(v) after the while loop... Any insight ?