1def no_it_isnt(list):
2 result = []
3 for item in list:
4 result.append(reverse_item(type(item))(item))
5 return result[::-1]
6
7def reverse_item(type):
8 if type is int or type is float:
9 return reverse_num
10 if type is str:
11 return reverse_str
12 if type is bool:
13 return reverse_bool
14
15 def default(item):
16 pass
17 return default
18
19def reverse_num(num):
20 return -num
21
22def reverse_str(str):
23 return str[::-1]
24
25def reverse_bool(bool):
26 return not bool
.....
----------------------------------------------------------------------
Ran 5 tests in 0.000s
OK
Георги Кунчев
18.10.2023 11:46Интересна концепция с всички функции и функции, които връщат функции. За текущата задача според мен е прекалено, но пък добре си си поиграла. Просто споменвам, че ако наистина трябва да решиш този проблем, една функция с 6-7 реда ще е напълно валидна и достатъчна.
|
f | 1 | def no_it_isnt(list): | f | 1 | def no_it_isnt(list): |
2 | result = [] | 2 | result = [] | ||
3 | for item in list: | 3 | for item in list: | ||
4 | result.append(reverse_item(type(item))(item)) | 4 | result.append(reverse_item(type(item))(item)) | ||
n | 5 | return result[-1::-1] | n | 5 | return result[::-1] |
6 | 6 | ||||
7 | def reverse_item(type): | 7 | def reverse_item(type): | ||
8 | if type is int or type is float: | 8 | if type is int or type is float: | ||
9 | return reverse_num | 9 | return reverse_num | ||
10 | if type is str: | 10 | if type is str: | ||
11 | return reverse_str | 11 | return reverse_str | ||
12 | if type is bool: | 12 | if type is bool: | ||
13 | return reverse_bool | 13 | return reverse_bool | ||
14 | 14 | ||||
15 | def default(item): | 15 | def default(item): | ||
16 | pass | 16 | pass | ||
17 | return default | 17 | return default | ||
18 | 18 | ||||
19 | def reverse_num(num): | 19 | def reverse_num(num): | ||
20 | return -num | 20 | return -num | ||
21 | 21 | ||||
22 | def reverse_str(str): | 22 | def reverse_str(str): | ||
t | 23 | return str[-1::-1] | t | 23 | return str[::-1] |
24 | 24 | ||||
25 | def reverse_bool(bool): | 25 | def reverse_bool(bool): | ||
26 | return not bool | 26 | return not bool |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|