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 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
`[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
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
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
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
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
_, 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
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
Note that `if len(result) > 0:` and `if result:` are equivalent for a list.
More
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
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
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
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
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