49
Phil15
30 56 64 Leader of the month
23157/ 25141
Last seen 2 hours ago
Member for 6 years, 3 months, 11 days
Difficulty Advanced
I was a math teacher in France for two years. I'm currently reconverting to IT, I'm here to improve my Python skills, and practice English.

Best reviews / Newest reviews
First-meta77fora
Do not overuse parentheses, while, return and ... are not functions: def beginning_zeros(number: str) -> int: i = 0 while number[i] == "0": i += 1 if len(number) <= i: break return i # It can even be def beginning_z More
Standard library:itertools-takewhile-PatrickFeiYu 1 1
Great use of takewhile function. Not the most obvious choice here. More
1-liner: numpy determinant-Stensen 2 2
So `checkio = np.linalg.det`. lambda is not always needed. If you see other solutions with rounding methods, it's because the mission lately evolved. More
4-liner: aim for the accuracy dawg-Stensen 1 1
I did not know about this log determinant, thanks. But I have to say that `_` is usually used for variables we don't use, such as for _ in range(5): print('Hi!') time.sleep(1) Here I had to see the doc to know it was the sign of the det. I could have guessed but I did not, the More
1-liner-Stensen 1 1
After I deobfuscated it, I would change `[...].pop()` for `next(...)` since it has a single element. And since we are in creative section, I would even add it is shorter by 2 chars. Or even shorter `[...][0]`, but I prefer next. _Next_ deobfuscated version: from calendar import Calendar fr More
First-Jonethan
* Use else when needed, we exit the function when we `return` something. * `not ... == ...` is the same as `... != ...`. * A number that does not finish with a zero does not seem to be a special case to me, but 0 does. * You do not really use the index, but you want to iterate on the string in a rev More
First-colinmcnicholl
Ahah, we wrote the same code. They are minor changes obviously but it is the same. More
filename.rpartition('.'), partial(sorted, key=...)-Phil15 3
@kudinov.feodor Well, a simple fix (keep separator in "name part"): def _sort_by_ext_key(filename): name, sep, ext = filename.rpartition('.') # assert sep in ('', '.') return (ext, name) if name else ('', sep + ext) More
First-juestr 1 1
Looking `delete` and since you imported product from `itertools`, I thought about `itertools.compress` I never used before, but it is appropriate here with a little change: exchange True and False (and reverse masks), which then mean "keep" instead of "delete". ```python from itertools import produ More
Three solutions + 1 in comments-Phil15
As I did for "replace first", I add this fourth solution: ```python # numpy.roll generalize our function. import functools as fn import numpy as np replace_last = fn.partial(np.roll, shift=1) ``` More
Three solutions + 1 in comments-Phil15 6 1
From another solution I "simplified", I would like to add a fourth one: ```python import functools as fn import numpy as np replace_first = fn.partial(np.roll, shift=-1) ``` More
Zigzag McQuack-Ilis 1 1
About `[[]] * rows`, be careful. >>> L = [[]] * 5 >>> L[0].append(1) >>> L [[1], [1], [1], [1], [1]] # Same object five times. More
Lambda with filter-swagg010164 1
No need to have sets. ranges are enough. Test if a number is in a range is fast too. More
First-DEADPOOL 1
`if res[i] != True` then `res[i]` is already `False`. so lines 7 - 11 can be much shorter. Plus two pythonic changes: def stones(pile, moves): res = [True] + pile * [False] for i in range(1, len(res)): for j in moves: if i - j > 0 and not res[i - j]: More
Too long-mlhardy.mh
def match(comp, test): count = 0 # you do not use the index j but comp[j] and test[j] for c, t in zip(comp, test): if c == t: count += 1 # "count == 2" is already True or False, return it return count == 2 # or def match More
First-Villentre
It's not 3rd party. Plus # You do not use the index i but a[i] and b[i]. def hamming(a, b): return sum(s != t for s, t in zip(str(a), str(b))) def is_doublet(numbers): # something with zip too to avoid the use of "i". More
find path-Olpag 1 1
Just in case you don't know from collections import defaultdict graph = defaultdict(list) # then graph[num1].append(num2) # instead of graph[num1] = graph.get(num1,[]) + [num2] Or without collections module graph.setdefault(num1, []).append(num2) More
BFS-rossras 1
Sum comprehension is great. def is_adjacent(i, j): '''Return true if x and y differ by one digit, false otherwise''' return sum(i_digit != j_digit for i_digit, j_digit in zip(str(i), str(j))) Great job! More
Combinatorics and nothing else-Vasily__Chibilyaev 1 1
`0 if m==n else 1` or just `m != n`. Booleans are integers 0 and 1, so we can sum them. More
Recursion-Freez 1
`min` has a default parameter that can be useful. And `len` is great function on its own. min(variants, key=lambda x: len(x)) if variants else False min(variants, key=len, default=False) More
1 2 3 4
5
6 7 8 9 10 11 12 13