13/18 I'm going nuts.. **double_list([0, 1]) returned [0, 1] instead of [0, 2]


Why is it returning the same value instead of doubling it?

My code is as such:

n = [3, 5, 7]

def double_list(x):
  for i in range(0, len(x)):
    x[i] = x[i] * 2
    return x

print double_list(n)


You’re returning the same value, but you’ve also modified it, though you haven’t finished modifying it


When I pass 3,5,7 to the function, aren’t I iterating through each element (3,5,7)?

x[i] means I go to 3 first, then replace it with 3*2, then … I return… the list. WAIT. I only modified the first value before returning it, is that right?


yes. it is.


oh my god thank you so much. I spent so much time on this problem before coming here. I guess this is a lesson on how important it is to make sure my indents are properly done.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.