-
Notifications
You must be signed in to change notification settings - Fork 1
/
029_Invert values.py
53 lines (33 loc) · 1000 Bytes
/
029_Invert values.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Codewars Coding Challenge
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.
https://www.codewars.com/kata/5899dc03bc95b1bf1b0000ad/train/python
"""
# My Solution
def invert(lst):
return [-x for x in lst]
"""
Sample Test
import codewars_test as test
from solution import invert
@test.describe("Invert values")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
test.assert_equals(invert([1,2,3,4,5]),[-1,-2,-3,-4,-5])
test.assert_equals(invert([1,-2,3,-4,5]), [-1,2,-3,4,-5])
test.assert_equals(invert([]), [])
"""
"""
Perfect Solution From Codewars
=1=
def invert(lst):
return [i*-1 for i in lst]
=2=
invert = lambda lst: [-e for e in lst]
"""