Skip to content

Latest commit

 

History

History
43 lines (24 loc) · 637 Bytes

Invert_values.md

File metadata and controls

43 lines (24 loc) · 637 Bytes

CodeWars Python Solutions


Invert values

Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.

invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []

You can assume that all values are integers. Do not mutate the input array/list.


Given Code

def invert(lst):
    pass

Solution

def invert(lst):
    return [n * -1 for n in lst] if len(lst) > 0 else []

See on CodeWars.com