1def no_it_isnt(args=[]):
2 isnt_args = []
3 for arg in reversed(args):
4 if isinstance(arg, bool):
5 isnt_args.append(not arg)
6 elif isinstance(arg, str):
7 isnt_args.append(arg[::-1])
8 else:
9 isnt_args.append(-arg)
10 return isnt_args
.....
----------------------------------------------------------------------
Ran 5 tests in 0.000s
OK
Георги Кунчев
19.10.2023 09:05Според мен трите отделни функции са излишни. Прекалено са прости, за да се отделят, но не държа да ги махаш. Твое е решението.
|
n | 1 | def rev_num(arg): | n | ||
2 | return -arg | ||||
3 | |||||
4 | def rev_bool(arg): | ||||
5 | return not arg | ||||
6 | |||||
7 | def rev_str(arg): | ||||
8 | return arg[::-1] | ||||
9 | |||||
10 | def no_it_isnt(args = []): | 1 | def no_it_isnt(args=[]): | ||
11 | isnt_args = [] | 2 | isnt_args = [] | ||
12 | for arg in reversed(args): | 3 | for arg in reversed(args): | ||
13 | if isinstance(arg, bool): | 4 | if isinstance(arg, bool): | ||
n | 14 | isnt_args.append(rev_bool(arg)) | n | 5 | isnt_args.append(not arg) |
15 | elif isinstance(arg, str): | 6 | elif isinstance(arg, str): | ||
n | 16 | isnt_args.append(rev_str(arg)) | n | 7 | isnt_args.append(arg[::-1]) |
17 | else: | 8 | else: | ||
t | 18 | isnt_args.append(rev_num(arg)) | t | 9 | isnt_args.append(-arg) |
19 | return isnt_args | 10 | return isnt_args |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def rev_num(arg): | f | 1 | def rev_num(arg): |
2 | return -arg | 2 | return -arg | ||
3 | 3 | ||||
4 | def rev_bool(arg): | 4 | def rev_bool(arg): | ||
5 | return not arg | 5 | return not arg | ||
6 | 6 | ||||
7 | def rev_str(arg): | 7 | def rev_str(arg): | ||
8 | return arg[::-1] | 8 | return arg[::-1] | ||
9 | 9 | ||||
10 | def no_it_isnt(args = []): | 10 | def no_it_isnt(args = []): | ||
11 | isnt_args = [] | 11 | isnt_args = [] | ||
12 | for arg in reversed(args): | 12 | for arg in reversed(args): | ||
13 | if isinstance(arg, bool): | 13 | if isinstance(arg, bool): | ||
14 | isnt_args.append(rev_bool(arg)) | 14 | isnt_args.append(rev_bool(arg)) | ||
15 | elif isinstance(arg, str): | 15 | elif isinstance(arg, str): | ||
16 | isnt_args.append(rev_str(arg)) | 16 | isnt_args.append(rev_str(arg)) | ||
17 | else: | 17 | else: | ||
18 | isnt_args.append(rev_num(arg)) | 18 | isnt_args.append(rev_num(arg)) | ||
19 | return isnt_args | 19 | return isnt_args | ||
t | 20 | t | |||
21 | print(no_it_isnt([1, -3.14, True, 'abc', 0])) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|