1def no_it_isnt(input_list) :
2 opposites = []
3
4 for item in input_list:
5 element_type = type(item)
6 if element_type in (int, float):
7 opposites.append(-item)
8 elif element_type == bool:
9 opposites.append(not item)
10 elif element_type == str:
11 opposites.append(item[::-1])
12
13 return opposites[::-1]
.....
----------------------------------------------------------------------
Ran 5 tests in 0.000s
OK
n | 1 | def no_it_isnt(list_input) : | n | 1 | def no_it_isnt(input_list) : |
2 | opposites = [] | 2 | opposites = [] | ||
3 | 3 | ||||
n | 4 | for item in list_input : | n | 4 | for item in input_list: |
5 | element_type = type(item) | 5 | element_type = type(item) | ||
n | 6 | if element_type == int or element_type ==float : | n | 6 | if element_type in (int, float): |
7 | opposites.append(-item) | 7 | opposites.append(-item) | ||
t | 8 | elif element_type == bool : | t | 8 | elif element_type == bool: |
9 | opposites.append(bool(item ^ 1)) | 9 | opposites.append(not item) | ||
10 | elif element_type == str : | 10 | elif element_type == str: | ||
11 | opposites.append(item[::-1]) | 11 | opposites.append(item[::-1]) | ||
12 | 12 | ||||
13 | return opposites[::-1] | 13 | return opposites[::-1] |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|