I have python code similar to the following
for a in range(0,x):
The generation of the list can be converted into a list comprehension, but the print statements cannot be done in one line:
x = 10 l1 = [a for a in range(0, x) if a % 2 == 0]
Will give you the list, if you want also the
def foo(a): print('Test1') print('Test2') return a l2 = [a for a in range(0, x) if foo(a) % 2 == 0]
This latter option is however "a code smell", generating a list while relying for output on the side-effect of a function is not a good practice (very error prone in an even moderately large program). I would not recommend the latter.