by R4R Team

Example-

list is l=[2,-3,4,-1]

Aim to obtain the this list [-2,3,-4,1]


program-

print("Enter number in list")
li=list(map(int,input().split()))

print("List is",li)

#first way
l=li
for i in range(len(l)):
l[i]=-l[i]

print("List become",l)

#second way

l=list(map(lambda x:-x,l))
print("List become",l)


output-

Enter number in list
1 -2 3 -4 1 6 -7
List is [1, -2, 3, -4, 1, 6, -7]
List become [-1, 2, -3, 4, -1, -6, 7]
List become [1, -2, 3, -4, 1, 6, -7]




Leave a Comment: