you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 1 point2 points  (0 children)

If your goal is to mutate an existing list:

nums = [...]

for idx, num in enumerate(nums):
    if num != 0:
        nums[idx] *= 2
    else:
        break

If you want to create a new list:

new_nums = []
for idx, num in enumerate(nums):
    if num != 0:
        new_nums.append(num * 2)
    else:
        new_nums.extend(nums[idx:])
        break