Предизвикателства > Полиморфичен негативизъм > Решения > Решението на Деян Диков

Резултати
1 точки от тестове
0 точки от учител

1 точки общо

5 успешни теста
0 неуспешни теста
Код

 1def no_it_isnt(expressions):
 2    rejecting = []
 3    for item in expressions:
 4        if type(item) in (int, float):
 5            item = -item
 6        elif type(item) is bool:
 7            item = not item
 8        elif type(item) is str:
 9            item = item[::-1]
10        rejecting.append(item)
11    return rejecting[::-1]

.....
----------------------------------------------------------------------
Ran 5 tests in 0.000s

OK

Дискусия
История

t1def no_it_isnt(lst):t1def no_it_isnt(expressions):
2    rejecting=[]2    rejecting = []
3    for i in lst:3    for item in expressions:
4        if type(i) in (int, float):4        if type(item) in (int, float):
5            i = -i5            item = -item
6        elif type(i) is bool:6        elif type(item) is bool:
7            i = not i7            item = not item
8        elif type(i) is str:8        elif type(item) is str:
9            i = i[::-1]9            item = item[::-1]
10        rejecting.append(i)10        rejecting.append(item)
11    return rejecting[::-1]11    return rejecting[::-1]
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def no_it_isnt(lst):f1def no_it_isnt(lst):
t2    for i in range(0, len(lst)):t2    rejecting=[]
3    for i in lst:
3        if type(lst[i]) in (int, float):4        if type(i) in (int, float):
4            lst[i] = -lst[i]5            i = -i
5        elif type(lst[i]) is bool:6        elif type(i) is bool:
6            lst[i] = not lst[i]7            i = not i
7        elif type(lst[i]) is str:8        elif type(i) is str:
8            lst[i] = lst[i][::-1]9            i = i[::-1]
10        rejecting.append(i)
9    return lst[::-1]11    return rejecting[::-1]
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op