list1=[-4,-1,0,3,10]
for k in list1:
list1.append(k**2)
I am trying to find the square of the numbers in list1 and then I am trying to add the square to the same list1. But it is going to infinity loop. Can some1 help me here
list1=[-4,-1,0,3,10]
for k in list1:
list1.append(k**2)
I am trying to find the square of the numbers in list1 and then I am trying to add the square to the same list1. But it is going to infinity loop. Can some1 help me here
may be something like this
list1=[-4,-1,0,3,10]
list2 = []
for k in list1:
list2.append(k**2)
list1 = list1 + list2
print(list1)
Or This
list1=[-4,-1,0,3,10]
list1 = list1 + [k**2 for k in list1]
print(list1)
Try this
>>> list1 = [-4, -1, 0, 3, 10]
>>> list1.extend([x**2 for x in list1])
>>> list1
[-4, -1, 0, 3, 10, 16, 1, 0, 9, 100]