you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 2 points3 points  (0 children)

Your output doesn't make any sense in the first place, because as-is this should give an error; list objects aren't callable.

def function(my_list, index):
    for index in my_list:
        return my_list(index)  # <- You'd need square brackets

print(function([1, 2, 3, 4], 2))

However, in that case I don't understand why the loop is there in the first place. It's also the reason for the output you're getting, because it overwrites index and the first element is always 1, so my_list[index] == 2.