List and Functions

n = [3, 5, 7]
def double_list(x):
  for i in range(0, len(n)):
    x[i] =x[i] * 2  
    return x[i] # x should be used.

expected result: 6,10,14
printed result: 6 :frowning: Help ?


Check the indentation on your return line.


Sir If I print x instead of x[i] it will print result in list form e.g: [6,10,14]. I am bit confused what is different between returning x[i] and x since both shows same output but in different way.


The function should modify the entire list and then return it. x[i] is only one element. x is the entire list.

Your code above has the return line inside the loop so it exits the loop on the first iteration.


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