1def special_negate(param):
2 """Perform a special Negation on a Param"""
3 return not param if isinstance(param, bool) else (
4 param[::-1] if isinstance(param, str) else (
5 -param if isinstance(param, (int, float))
6 else None
7 )
8 )
9
10
11def no_it_isnt(list_to_be_negated):
12 """Perform a special Negation on a List reversed"""
13 return list([special_negate(i) for i in list_to_be_negated[::-1]])
.....
----------------------------------------------------------------------
Ran 5 tests in 0.000s
OK
Георги Кунчев
18.10.2023 11:29Не бих го написал така, но нямам абсолютно нищо против записа ти. Чете се лесно. Ясно е какво прави. Добре е.
|
Филип Филчев
17.10.2023 22:21Относно форматирането на първата функция, за мен е по-четимо. Ако е неправилно, ще наблъскам всичко на 1 ред
|
f | 1 | def special_negate(param): | f | 1 | def special_negate(param): |
2 | """Perform a special Negation on a Param""" | 2 | """Perform a special Negation on a Param""" | ||
3 | return not param if isinstance(param, bool) else ( | 3 | return not param if isinstance(param, bool) else ( | ||
4 | param[::-1] if isinstance(param, str) else ( | 4 | param[::-1] if isinstance(param, str) else ( | ||
5 | -param if isinstance(param, (int, float)) | 5 | -param if isinstance(param, (int, float)) | ||
6 | else None | 6 | else None | ||
7 | ) | 7 | ) | ||
8 | ) | 8 | ) | ||
9 | 9 | ||||
10 | 10 | ||||
11 | def no_it_isnt(list_to_be_negated): | 11 | def no_it_isnt(list_to_be_negated): | ||
12 | """Perform a special Negation on a List reversed""" | 12 | """Perform a special Negation on a List reversed""" | ||
t | 13 | return list([special_negate(i) for i in list_to_be_negated]) | t | 13 | return list([special_negate(i) for i in list_to_be_negated[::-1]]) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def special_negate(param): | f | 1 | def special_negate(param): |
2 | """Perform a special Negation on a Param""" | 2 | """Perform a special Negation on a Param""" | ||
3 | return not param if isinstance(param, bool) else ( | 3 | return not param if isinstance(param, bool) else ( | ||
4 | param[::-1] if isinstance(param, str) else ( | 4 | param[::-1] if isinstance(param, str) else ( | ||
5 | -param if isinstance(param, (int, float)) | 5 | -param if isinstance(param, (int, float)) | ||
6 | else None | 6 | else None | ||
7 | ) | 7 | ) | ||
8 | ) | 8 | ) | ||
9 | 9 | ||||
10 | 10 | ||||
11 | def no_it_isnt(list_to_be_negated): | 11 | def no_it_isnt(list_to_be_negated): | ||
12 | """Perform a special Negation on a List reversed""" | 12 | """Perform a special Negation on a List reversed""" | ||
t | 13 | return list([special_negate(i) for i in list_to_be_negated[::-1]]) | t | 13 | return list([special_negate(i) for i in list_to_be_negated]) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|