My professor used the following code:
def eq(x):
return x+1
test = [1,2,3,4,5,6]
result = [eq(each_solution) for each_solution in test]
It works as we would think, result is:
[2, 3, 4, 5, 6, 7]
I expected this output but I don't know how or why the line
result = [eq(each_solution) for each_solution in test]
work and should work, as usual we would put the eq(each_solution) in the for (although not like that inside a list), not behind. if we just put the line eq(each_solution) for each_solution in teste as expected, it won't work. But in a list [] it functions properly, why? I've never seen a For like that before.
Also what would you recommend to do if not that? There are other options?