I am trying to understand list comprehension by passing a list a of functions to act on list as shown in the code below.
def fun1(x):
x.append(5)
print(" In Fun 1:")
print(x)
return x
def fun2(x):
x.append(6)
return x
def fun3(x):
x.append(7)
return x
int_list = [1, 2, 3, 4]
funs_family = (fun1, fun2, fun3)
new_list = [fun(int_list) for fun in funs_family ]
print(new_list)
I am expecting the result of the new_list to be
[1,2,3,4,5] [1,2,3,4,5,6] [1,2,3,4,5,6,7]
but the actual result is
[1,2,3,4,5,6,7] [1,2,3,4,5,6,7] [1,2,3,4,5,6,7]
Can anyone explain why the actual result is different from expected result?