How do you switch a negative to a positive and a postive to a negative in a list?
I want to make a function to do this. For example [1,-3, 5]
would become [-1, 3, -5]
How do you switch a negative to a positive and a postive to a negative in a list?
I want to make a function to do this. For example [1,-3, 5]
would become [-1, 3, -5]
Just use list comprehension:
a = [1, -3, 5]
negative = [-x for x in a]
print(negative)
Output:
[-1, 3, -5]