Working on a codefights problem. Got stuck on the solution, or rather, solving the way codefights wanted me too. Here is the solution
def listBeautifier(a):
res = a[:]
while res and res[0] != res[-1]:
a, *res, d = res
return res*
I did some printing of the result to try and understand what's going on and some experimentation to see how it works. From what I gathered, printing out various tests, the first item of res get's assigned to a and the last to d (which remain unused). Then, res is unpacked and each element of res is reassigned as the remaining bit of the list. I tried the following code
def listBeautifier(a):
res = a[:]
while res and res[0] != res[-1]:
a,c, *res, d = res
return res*
which threw an error so I gather this must be done symmetrically. What is python doing exactly? I see what's happening but not how.