39
CDG.Axel
18 36 55 Leader of the month
9398/ 9695
Axel
Last seen 1 month ago
Member for 2 years, 8 months, 23 days
Difficulty Normal
Best reviews / Newest reviews
First-dig 4 2
Optimization ideas: --> # first step: removed List (used once), space as argument of split(), and useless condition counter=0 for word in text.split(): if word.isdigit(): counter += int(word) return counter --> # next step - comprehension with if More
Walrus :)-suic 3
you need no walrus and if-comprehension: return sum( max(0 ,(min(d2, end_watching or d2) - max(d1, start_watching or d1)).total_seconds()) for d1, d2 in zip_longest(*[iter(els)] * 2, fillvalue=end_watching) and zip_longest too: for d1, d2 in zip(els[::2], els[1::2] + [ More
Reverse String (second)-tssrkt777 3 1
best way to reverse string, imo :) More
First-dx2-66 2
Cool solution! Btw there is some tricks for improve code and make it clear: * list(map(list())) is too heavy, simple list comprehension is enough * my_list[::(-1) ** row] for reverse every odd line and save your filling idea return list(map(list, [r[...] if i%2 else r[...] for i in range(r More
Shame on me for the previous one-belka-fiz 2 1
Это решение точно смотрится лучше предыдущего. Но тоже есть что поправить :) Для начала хотя бы так: datetime(1970, 1, 1, 0, 0, 0) --> datetime.max datetime(9999, 12, 31, 23, 59, 59)) --> datetime.max Далее, раз вы уже используете цикл по zip, прямо напрашивается сделать так: i More
Return Find()-paf 2
As for me, four strings for such task is too much :) p = text.find(symbol, text.find(symbol) + 1) return None if p < 0 else p More
Prod and list-paf 2 1
There are some tricks to optimize solution: # original code return prod([int(i) for i in list(str(number).replace('0', ''))]) # most of python functions accept generators --> return prod(int(i) for i in list(str(number).replace('0', ''))) # you can easily iterate strin More
Split Pairs-tssrkt777 2 1
Shortest code with no re.findall :) More
2 Solutions in 1-Alex_4444D 2
Very familiar solution in comments :) My last version is 5 lines only... More
First-nomis517 2
code will be faster if replace sum with len More
Isdigit?-paf 2 1
Можно чуть пооптимизировать: return sum([int(i if i.isdigit() else 0) for i in text.split()]) --> return sum(int(i if i.isdigit() else 0) for i in text.split()) # суммируем генератор, а не список --> return sum(int(i) for i in filter(str.isdigit, text.split())) # предварите More
Remove All Before-tssrkt777 2 1
Great! Btw... return items[items.index(border) if border in items else 0:] More
Army Battles-tssrkt777 2 1
Слишком страшная функция def fight(self, army1, army2) :) Можно сделать так... Запилить isalive для армии Просто использовать функцию fight(), которая у вас уже есть В зависимости от того, что вернет функция, убивать элемент либо из первого списка, либо из второго... class Battle: de More
Just isupper()-paf 2 1
Constructions like 'True if condition1 else condition2' looks strange, and may be replaced with 'condition1 or condition2' return True if not text.replace(' ', '').isalpha() else text.isupper() --> return not text.replace(' ', '').isalpha() or text.isupper() Btw for this task you can s More
Morse Decoder-tssrkt777 2 1
И опять слишком похоже на C++ :) Есть несколько хитростей, чтобы сократить функцию до одной строчки 1. Добавьте в MORSE такое значение - "": "*", и посмотрите, во что превратится code.split(' '). Это позволит вам избавиться от цикла по словам. 2. Используйте comprehension вместо внутреннего цикла ( More
Nothing special-Kolia951 2 1
I love conditions in python! if result >= 0 and result <= 180: return result else: return "I don't see the sun!" --> return result if 0 <= result <= 180 else "I don't see the sun!" And you can optimize angle calclulations: all code --> result = 15 * in More
Nothing special-Kolia951 2 1
Slices is the best way to improve code: even_positions_sum = 0 for i in range(0, len(array), 2): even_positions_sum += array[i] --> even_positions_sum = sum(array[::2]) And avoid exceptions: try: last_digit = array[-1] except: last_digit = 0 More
The Warriors-tssrkt777 2 1
Для для is_alive можно использовать декоратор \@property. Уберет кучу строчек кода (минимум 4) @property def is_alive(self): return self.health > 0 More
First-Sebdidier 2 1
a slightly longer in symbols than with zip, but faster return sum([(b - a).total_seconds() for a, b in zip(els[::2], els[1::2])]) More
First-dig 2 1
Wooow, it's too hard to understand for me. But solution is pretty easy. 1. Filter string from anything except brackets 2. Replace '()' or '[]' or '{}' pair with the empty string 3. Add solt to taste (repeat while you have any to replace) 4. If result is empty string - expression is correct Btw... More