49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 1 hour 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.
`replace_all('qwerty', '.', '')` would return `''` because `.` as a regex match any character.
There is sadly no test about this.
To avoid that (do we want to avoid that?), `re.escape` would be useful (but then why use "re" at all?).
def replace_all(mainText: str, target: str, repl: str) -> s
More
This is an obfuscation of [my 3rd party solution](https://py.checkio.org/mission/blood-distribution-3/publications/Phil15/python-3/scipy-19-milp-mixed-integer-linear-programming/). Tricks here:
- `integrality=0,` and `lb=0,` are actually default values so I didn't need to write those
- 1-letter na
More
Note: Here, `max` would be enough by itself (because isoformat is sortable by design), but it would be easy to change this solution to consider other datetime formats, something like:
get_latest = functools.partial(max, key=lambda s: datetime.datetime.strptime(s, '%H:%M %d/%m/%Y'))
More
You can write `int` instead of `lambda: int()`. A simple dict with "(int, int)" keys would be enough. And the returned value is surely equal to `dp[i][weight]`. I prefered using a list but defaultdict is also nice.
More
Or a more "complex" unpacking instead of the whole try/except block:
value, weight, limit, *_ = item + (total_weight,)
# there is also this below but I don't like it.
value, weight, limit = (item + (total_weight,))[:3]
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
If you are reading this solution and asking yourself why this solution can even be publish (the function signature being clearly incorrect), it's because:
1. The mission (at the very beginning) did not have the second parameter which was latter added (to make it really different from another palind
More
As the mission author, I receive emails about new solutions and saw the title of your solution and I'm glad you liked my task. =)
More
Don't you think you spam published solutions?! 6 (very very similar) published solutions.
More
Just so you know, instead of `num.insert(0, rem)`, you could have done `num.append(rem)`. The elements of `num` would be reversed, but it would not change the final result. That and `append` is contant time (`O(1)` complexity, it just add the element at the end) while `num.insert(0, ...)` does `len(
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
I think the "checkio" function should receive only one “step info” each time and process it, instead of giving the entire history, and a coroutine is a good way to do just that. Plus, it's a rare occasion to use `typing.Generator` in a meaningful way.
More
You don't need "nonlocal" here.
In a new example, define variable "s" inside "g" is okay, but we can't use the "s" outside for it.
>>> def f(n):
s = []
def g(i):
s = s + [i**2]
for i in range(n):
g(i)
return s
>>> f(5)
Traceback
More
Compare with `>` already give a boolean, you can just return the (boolean) comparison:
return items.count(True) > items.count(False)
More
Coming back to it 19 months later, I still understand it clearly. It makes me happy. ✨
And the only thing I would really change is:
No need of the variable "okay" in the "possible_words" function: the "else" clause would do the job.
changes = []
for rc, letter in z
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
Note that `if len(result) > 0:` and `if result:` are equivalent for a list.
More
**EDIT:** in the arguments are of the **same** lengths.
More