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
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
Standard library:itertools-takewhile-PatrickFeiYu 1 1
Great use of takewhile function. Not the most obvious choice here. More
First-Divya_Amin 1
You do not really use `i` but `number_str[i]` so for digit in number_str: list_num.append(int(digit)) Second, list comprehension is great list_num = [int(digit) for digit in number_str] Third, or just return max(int(digit) for digit in str(number)) More
Respect the grid boundaries & Play With DIRS navigation-Stensen 1 1
I don't see why you need to catch index errors since you check `_c` and `_r` are good. Plus `r` and `c` are good names. def count_neighbours(grid, row, col): return sum( grid[r][c] == 1 for move in DIRS for r, c in [map(add, (row, col), DIRS[move])] More
Dijkstra algorithm for weighted graph-2010min0ru 1 1
I like to refactor a bit so here: types and a few simplifications/tricks... ```python from collections import defaultdict from typing import Defaultdict, List, Tuple # GraphCosts = defaultdict(lambda: defaultdict(int)) # Not a type but a dict. GraphCosts = Defaultdict[str, Defaultdict[str, int]] 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
search and destroy-Adrian_Goh 1 1
while ...: for pair in '()', '[]', '{}': sstr = sstr.replace(pair, '') return not sstr 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
New battle.fight method, and a different management of attributes/method.-Phil15 1
With _lancers_ who can attack _two units_, I felt the need to _start over_, looking at future missions, to have a more global view of these missions. 1) Battle.fight method and management of the dead warriors (Army properties) are completely reviewed to allow lancers to hit a second unit. 2) Differ More
First-sanjieyu 1 1
Do you know about `map`? I like the key argument and list comprehensions but sometimes, `map` can be quite useful: len(max(rows, key = len)) # or max(map(len, rows)) ["".join(item) for item in zip(*rows)] # or map("".join, zip(*rows)) # could be list(map...) to be reall 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
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
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
First-derrickding95 3
`range(len(...))` is useless is most cases, `enumerate` is great: for i, (A, B) in enumerate(pairs): ... I don't understand why you use `deepcopy` since there is no change in tree variable. And the final `return` (in `search` function) is useless too. More
1 2 3 4 5
6
7 8 9 10 11 12 13