When the answer is a list and not a number, building a new one is nearly always easier and safer than trying to change the one you have.
out = []for v in values:if v != 0:out.append(v)return out + [0] * (len(values) - len(out))
[0] * 3 is [0, 0, 0]; + joins two lists end to end.There is a short form: [v for v in values if v != 0]. This is a list comprehension and does the same as the loop above. Use it while it reads easily; once it holds two conditions and a calculation, go back to the loop.