1def no_it_isnt(values):
2 '''The function returns a list with the opposite values'''
3 result = []
4 for value in values:
5 if isinstance(value, bool):
6 result = [not value] + result
7 elif isinstance(value, str):
8 result = [value[::-1]] + result
9 elif isinstance(value, (int, float)):
10 result = [-value] + result
11 return result
.....
----------------------------------------------------------------------
Ran 5 tests in 0.000s
OK
f | 1 | def no_it_isnt(values): | f | 1 | def no_it_isnt(values): |
2 | '''The function returns a list with the opposite values''' | 2 | '''The function returns a list with the opposite values''' | ||
3 | result = [] | 3 | result = [] | ||
4 | for value in values: | 4 | for value in values: | ||
5 | if isinstance(value, bool): | 5 | if isinstance(value, bool): | ||
6 | result = [not value] + result | 6 | result = [not value] + result | ||
7 | elif isinstance(value, str): | 7 | elif isinstance(value, str): | ||
8 | result = [value[::-1]] + result | 8 | result = [value[::-1]] + result | ||
9 | elif isinstance(value, (int, float)): | 9 | elif isinstance(value, (int, float)): | ||
10 | result = [-value] + result | 10 | result = [-value] + result | ||
11 | return result | 11 | return result | ||
t | 12 | t | |||
13 | print(no_it_isnt([1, -3.14, 6, 7, -8, True, 'abc', 0, 'c', -0.0, -0.0])) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def no_it_isnt(values): | f | 1 | def no_it_isnt(values): |
2 | '''The function returns a list with the opposite values''' | 2 | '''The function returns a list with the opposite values''' | ||
3 | result = [] | 3 | result = [] | ||
4 | for value in values: | 4 | for value in values: | ||
5 | if isinstance(value, bool): | 5 | if isinstance(value, bool): | ||
n | 6 | result.insert(0, not value) | n | 6 | result = [not value] + result |
7 | elif isinstance(value, str): | 7 | elif isinstance(value, str): | ||
n | 8 | result.insert(0, value[::-1]) | n | 8 | result = [value[::-1]] + result |
9 | elif isinstance(value, (int, float)): | 9 | elif isinstance(value, (int, float)): | ||
n | 10 | result.insert(0, -value) | n | 10 | result = [-value] + result |
11 | return result | 11 | return result | ||
t | t | 12 | |||
13 | print(no_it_isnt([1, -3.14, 6, 7, -8, True, 'abc', 0, 'c', -0.0, -0.0])) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def no_it_isnt(values): | f | 1 | def no_it_isnt(values): |
n | 2 | '''The function gets a list of values and | n | 2 | '''The function returns a list with the opposite values''' |
3 | returns a list of the opposite values of the elements | ||||
4 | in reversed order''' | ||||
5 | result=[] | 3 | result = [] | ||
6 | for value in values: | 4 | for value in values: | ||
7 | if isinstance(value, bool): | 5 | if isinstance(value, bool): | ||
8 | result.insert(0, not value) | 6 | result.insert(0, not value) | ||
9 | elif isinstance(value, str): | 7 | elif isinstance(value, str): | ||
10 | result.insert(0, value[::-1]) | 8 | result.insert(0, value[::-1]) | ||
11 | elif isinstance(value, (int, float)): | 9 | elif isinstance(value, (int, float)): | ||
t | 12 | result.insert(0, value if value == 0 else -value) | t | 10 | result.insert(0, -value) |
13 | return result | 11 | return result |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|