The above code is correct, but it is inefficient. List comprehensions are meant for case like this. The idea of comprehension is to move the for loop inside the construction of the result list:def get_square_list(x): return [xi*xi for xi in x]
This is both simpler and faster than the previous code.
Definitely worth reading if you come at Python from a C-like language background.