🌶️🌶️
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)
Perfect!
My only remark would be to use better variable names versus single letters such as "n".
https://trinket.io/python3/95c7179ec6
Hi, I couldn't see the completed code in your trinket link.
I have done mine. Here is my code....
return [x**2 for x in lst]
squared_list = square_list(data)
print(squared_list)
Output:-
[1, 4, 9, 16]
Very good use of list comprehension! Good job!
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)
Perfect!
My only remark would be to use better variable names versus single letters such as "n".
https://trinket.io/python3/95c7179ec6
Hi, I couldn't see the completed code in your trinket link.
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]
Very good use of list comprehension! Good job!