Taking the square root of each number in a list.
For this problem in the sqrt_list function:
- Take the square root of each item in the list,
- Store each squared item in another list, and
- Return this list.
list(11,22,33) def sqrt_list(list): ret = [] for i in list: ret.append(i %) return ret
CodePudding user response:
Maybe this?
# Use this import for all examples
from math import sqrt
old = [1,2]
new = [sqrt(x) for x in old]
Function form
def sqrt_list(old):
return [sqrt(x) for x in old]
or
def sqrt_list(old):
new_list = []
for i in old:
new_list.append(sqrt(i))
return new_list
Where:
print(sqrt_list([11, 22, 33]))
outputs:
[3.3166247903554, 4.69041575982343, 5.744562646538029]