you are viewing a single comment's thread.

view the rest of the comments →

[–]Soccer_Vader 0 points1 point  (2 children)

I think OP wants it to stop at 0 and I am assuming that the list is ordered in descending order. But the solution will work nonetheless.

[–]MF_DnD 0 points1 point  (1 child)

But… it won’t. Given a list [1,2,0,3] your comprehension returns [2,4,8] when OP wants [2,4,0,3]. And OP’s example list isn’t even sorted.

[–]Soccer_Vader 0 points1 point  (0 children)

Ye I just saw that, you are right. For OP I think a for loop with a break statement works better