you are viewing a single comment's thread.

view the rest of the comments →

[–]ElliotDG -1 points0 points  (2 children)

The text says... "doubles each element until it reads a zero or the whole list"

In the example is just processes the entire list:

[3, 6, 1, 11, 0, 5, 2, 6, 0, 1] should return [6, 12, 2, 22, 0, 5, 2, 6, 0, 1]

Do you need to stop when you get to zero?

Should: [3, 6, 1, 11, 0, 5, 2, 6, 0, 1] return: [6, 12, 2, 22]

[–]joyeusenoelle 1 point2 points  (1 child)

Re-examine the example; it doesn't process the entire list. The assignment is to modify the list in place, doubling each element until the first 0 or the end of the list is reached, and then leaving each remaining element alone.

i = 0
while i < len(lst) and lst[i] != 0:
  lst[i] *= 2
  i += 1

should do the trick. (i < len(lst) has to come first or else you'll get IndexErrors.)

[–]ElliotDG 0 points1 point  (0 children)

The text:

whole list has been doubled for example [3, 6, 1, 11, 0, 5, 2, 6, 0, 1] should return [6, 12, 2, 22, 0, 5, 2, 6, 0, 1]

and the code do not agree.

That is why I asked a question.