49
Phil15
30 56 64 Leader of the month
23067/ 25141
Last seen 2 hours ago
Member for 6 years, 2 months, 27 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
enumerate-rodka81 1
I kinda like it. It would be a bit ineficient to iterate over an entire book and list all indexes but indexes = (i for i, a in enumerate(text) if a == symbol) next(indexes, None) # first or None return next(indexes, None) # second or None More
13-liner: check every single words permutations-Stensen 1 1
`[crossword[i] for i in (0, 2, 4)] == crossword[::2]` More
Lateral thinking-Samuele_Baracani 1 1
Great, I think I did not thought of `title` method. But to make it a bit simplier: def to_camel_case(name): names = name.replace('_', ' ') return names.title().replace(' ', '') # delete spaces `join` is not the only useful method 😉 More
As simple as I can-Samuele_Baracani 1 1
You do not need to make a list, args is a tuple (which is "like" an immutable list). # example: checkio(1, 2, 3) # args = (1, 2, 3) (type tuple) # your list: [1, 2, 3] (type list) # there are not the same but they behave the same in this situation. def checkio(*args): More
perimeters-ogoro 1 2
Well it is clearly nicely short. After looking tests, which seem to be strong enough, I must admit it has to be right. Then I thought about it... And while I easily admit than every line has to be in a "perimeter" in one way or the other, I have hard time understanding why it is sufficient to have More
indexes-ogoro 1 1
First, it is great to not run so algorithm on the tree for each pair. It's nearly perfect. The only thing I don't like here is about `index_prefix`. We can for example have `str(10)==str(1)+str(0)` hence have the same `index_prefix` without being on the same path. The easiest fix would be to have More
With dict of hashlib functions, utf-8 encode, hexdigest-Phil15 1
I should have obviously use `getattr(hashlib, algorithm)` or `hashlib.new(algorithm)` instead of `func[algorithm]` and big `func` dictionary. There is nothing to like here, please do not like this. More
Markov chain, numpy, scipy.sparse.spdiags-Phil15 1
@ogoro Just after looking your recent publication for this mission, I've dug up my [old solution](https://py.checkio.org/mission/box-probability/publications/Phil15/python-3/markov-chains/) and improved it. It's still "good" math but I found "spdiags" that handles matrix diagonals the right way. I More
scanner with code dictionary-ogoro 1 1
You asked me why no-one seems to use `re.Scanner` for this. Well personally I did not know it, I probably looked at it someday and forgot about it (or not after writing this message). I just went to the documentation and type `help(re.Scanner)` and I still don't know what it does exactly. Looking a More
all lines found twice-juestr 1 1
To answer your comment on my solution, I agree. Liked solutions are not necessarily the best ones. But I give you a boost. Just for fun, I considered making it shorter with this, not necessarily better: from collections import Counter from itertools import combinations, starmap line_c More
graphlib.TopologicalSorter-juestr 1 1
Great, I tried with graphlib a bit (I asked oduvan to support the graphlib module) but it did not feel great for the task. But it's nice to see this. And "match/case" seems useful here. More
16-liner: rapid fire-przemyslaw.daniel 1
_, size, split = distance[0] # smallest item without popping it split += 1 heapreplace(distance, (split/size, size, split)) # faster than heapop followed by heappush It's still `O(log n)` but the factor is a bit lower. After testing this change on all tests 10000 More
First-bravebug 1 1
The sequencer part is a bit weird, you don't need it. `triangular_numbers` can be a generator function itself. That's why I wrote this, what comes next is more optional. Second, insert an element at the beginning of the list suggest you instead need a queue (or we could append to a list, and rever More
Explained-Selindian 1 1
Note that `if len(result) > 0:` and `if result:` are equivalent for a list. More
binary search-Lemmi 1
A recursive "binary search" on such small list is quite overkill, but why not. However, it's already implemented in the standard library: from bisect import bisect def ryerson_letter_grade(pct: int) -> str: return MARKS[bisect(POINTS, pct) - 1] (Tested on all possible percentages: More
always return to start-Sim0000 1 1
The first precondition > You can collect all gems in any possible order (otherwise it would be far more difficult). is there to ensure there is not multiple rooms (without suggesting strongly connected components too much). Or more precisely, gems are in a single strongly connected component acces 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
9-liner: generator with itertools.accumulate for altitudes-Phil15 1
I could have explain the two last lines. **line 16:** A flood zone starts at index i if the current altitude is found again, strictly after. If not then water can't be here. This assures index i is underwater. Since we enumerate possibles index, the first time altitudes.index don't raise a ValueErr More
A derelict battery-veky 1 2
Nice treasure from the deprecated stdlib. Only looking at docs, I could not find this gem. Curious, I looked the source code (with "inspect.getsource") and saw a comment "_This will die of IndexError when counter is too big_". So after some calls, I found out that it fails for 4000 (and bigger numb More
Short but inefficient-HeNeArKr 1 1
There is, hopefully, another way to guarantee that without sorting the entire set, your key function just have to be more precise, with lexicographic order. lambda x: (abs(x-target), x) More
1 2 3 4
5
6 7 8 9 10 11 12 13