7 Comments
User's avatar
Ed Silva's avatar

data = [1, 2, 3, 4]

def square_list(lst):

y = []

for x in (range(len(lst))):

y.append(lst[x] ** 2)

return(y)

n = square_list(data)

print(n)

Ardit Sulce's avatar

My only remark would be to use better variable names versus single letters such as "n".

Ardit Sulce's avatar

Hi, I couldn't see the completed code in your trinket link.

Vinod VV's avatar

I have done mine. Here is my code....

data = [1, 2, 3, 4]

def square_list(lst):

return [x**2 for x in lst]

squared_list = square_list(data)

print(squared_list)

Output:-

[1, 4, 9, 16]

Ardit Sulce's avatar

Very good use of list comprehension! Good job!