49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 20 minutes 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 suggested you OOP thanks to veky's solution. You can look it, it also defines a `__lt__` method, but it's more readable/simpler.
More
"Take the least taken detais" (with counter stock most_common) is a good strategy with really readable code IMO (if we know Counter of course).
join decorator was copied from another of my scripts making what remains pretty IMO.
More
You could use `float('inf')` or `from math import inf` for min_cost.
And global variable are tricky to use. You can define a function into another. Then you won't have to use a global variable.
def cheapest_flights():
min_cost = float('inf')
def cost_calc():
# cost_
More
Great use of numpy and scipy! I like the simplicity that these modules offer to your code, except lines 24-31, I would like a function similar to `pad` to reduce the matrix. :-) Or apply pad function only if it's necessary.
More
with `sum([...])` instead of `sum(...)`, you store an entire list before doing the sum.
`for p in list_of_one_element` to not write the expression twice is a good idea but here, `float_expression.is_integer()` can do the job.
yours: sum([p==int(p)for a in range(int((2*n)**.5))for p in[(2*n-
More
Lines 30-33 could be a single line with future python 3.8:
while next_cells := neighboring_area(cells) - obstacles:
...
See more in the description of [PEP 572](https://www.python.org/dev/peps/pep-0572/).
More
For my solution, I finally compared the use of a priority queue with a stack (so a list, like a DFS implementation) and a queue (like a BFS implementation). To do minimal changes, here my changes:
```python
# Instead of
from heapq import heappop, heappush
# For use a list instead of the priority qu
More
### Timings
Well first, I executed your code on all check tests. It is (with debug lines commented, because create strings for these lines took time) **2.4 times** slower than mine. Thanks to `import cProfile; cProfile.run('''tests block''', sort='tottime')`, I know it's because of `next_living_war
More
write a function to avoid to write the "same thing" three times:
def some_function_name(a, b, c):
return round(m.degrees(m.acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b))))
`while` should be `if`
`return [0, 0, 0]` is enough, no need to write `list(some_list)`.
More
More creative than clear IMO.
No need of parenthesis around `float` or around no rounded result: `round((...), 2)` -> `round(..., 2)`.
More
L[0 if (20 > age or 40 < age) else 1]
# or just
L[20 <= age <= 40]
Why does it work? `20 <= age <= 40` is a boolean True/False, which are integers: `True == 1 and False == 0`.
More
Personaly I don't like too much "append", I prefer to yield things. Less code can be more readable. It still not readable enough for me (too much indexes) but it's a start.
def rectdiff(r1, r2):
if r1[0] < r2[0]:
yield r1[0], r1[1], min(r2[0], r1[2]), r1[3]
if r1[2]
More
Ahah, we wrote the same code. They are minor changes obviously but it is the same.
More
* Use else when needed, we exit the function when we `return` something.
* `not ... == ...` is the same as `... != ...`.
* A number that does not finish with a zero does not seem to be a special case to me, but 0 does.
* You do not really use the index, but you want to iterate on the string in a rev
More
Do not overuse parentheses, while, return and ... are not functions:
def beginning_zeros(number: str) -> int:
i = 0
while number[i] == "0":
i += 1
if len(number) <= i:
break
return i
# It can even be
def beginning_z
More