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.
if you don't need init method in Battle class, don't write it.
len(army1.units) != 0 #or bool(army_units) line 102
#you can consider Army like a list with
class Army(list):
...
I like your management of behind units.
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 can consider Army like a list with
class Army(list):
...
I would prefer kick like method of the warrior class and
unit.kick(enemy_1, enemy_2)
Maybe a second_warrior method in Army class for simplify battle fight.
More
You don't need to iterate on the text. You're almost lucky it even works.
def correct_sentence(text: str) -> str:
text = text[0].upper()+text[1:]
if text[-1] != ".":
text += "."
return text
More
Note that when I published this I could not put it in **creative** category where it clearly belongs.
More
If you think Army like a list, consider
class Army(list):
#Army is now a list with all methods from list and your mind.
#So no need of init, getitem, len, remove.
More
All tests in a quarter of a second on my computer. Fast enough for me.
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
If the iterable is not necessarily a "list of lists of ... of ints/floats", but an "iterable of iterables of ... of not iterables".
def how_deep(iterable) -> int:
try:
return 1 + max(map(how_deep, iterable), default=0)
except TypeError: # not an iterable anymore, re
More
I really like the fact you use **corners** (so +2). I thought about it too, but my solution worked without this kind of deduction.
Line 54: `for v in range(1, 100):` or `for v in count(1):` itertools count, it's great.
I like to see exceptions raised, but you should create your own exception to be
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
@FromSnakeToPython Glad you liked the task. I enjoyed solving the task algorithmically more than manually.
More
I failed trying to import `label` in a simple short line some time ago, so I'm glad to see it.
_But I don't understand why `'object'` in `fromlist` make it work._
More
### I am particularly proud of my partition generator. _I think it is really beautiful thing!_
I noticed with other codes that "test(i,j)" can be replaced by "(i>j)-(iMore
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
Following... I understand why you use self.defense=0 on units without this attribute, but it's different to have the attribute = 0, and don't have the attribute. For 8th mission (it's not for today), this wouldn't be a great idea at all. hasattr function is useful on that point.
Anyway, fight funct
More