Writing 'for' and 'if' in a list makes code simple

a = [1,2,3,4,5]
b = [i**2 if i>3 else i for i in a]

print(b)

# result is [1, 2, 3, 16, 25]