49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
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.
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
Great use of takewhile function. Not the most obvious choice here.
More
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
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
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
`[crossword[i] for i in (0, 2, 4)] == crossword[::2]`
More
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
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
while ...:
for pair in '()', '[]', '{}':
sstr = sstr.replace(pair, '')
return not sstr
More
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
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
@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
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
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
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
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
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
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
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
`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