What Alternative can I use instead of .append in the below code
arr=[]
for i in range (1,15):
arr.append(i*i)
print (arr)
What Alternative can I use instead of .append in the below code
arr=[]
for i in range (1,15):
arr.append(i*i)
print (arr)
arr = [i*i for i in range(1,15)]
print(list(map(lambda i: i*i, range(1,15))))
The above is another method using lambda in just a single line, but it is a little bit complicated than list comprehension.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.