49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 9 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.
### 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
As I did for "replace first", I add this fourth solution:
```python
# numpy.roll generalize our function.
import functools as fn
import numpy as np
replace_last = fn.partial(np.roll, shift=1)
```
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
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
`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
You can annotate with nearly whatever you want, but here `int` annotation is not useful, and `list` annotation is (useless and) just wrong in the sense that "map" returns an object that is not a list at all.
"max" returns an integer (because "lnumber" is an iterable of integers), hence no need to c
More
For critical readers: strip('\n') can be replaced by strip().
More
WOW, it's totally unexpected!
From what I understand, `V[S[2:14]][S[4506:4512]](x,10)[0]` is equivalent to `vars()['__builtins__']['divmod'](x,10)[0]` so `divmod(x, 10)[0]` which is `x//10`. I tested it first on a shell on my machine before the checkio editor, it did not work on my machine. `__buil
More
I really like the use of **data.get** but sorting the all dict just for read the first element, it's not pretty at all!
The built-in function **max** is much more efficient here.
best_stock = lambda data: max(data, key=data.get)
More
You can use max function instead of sorting the all dict for just look the first element.
def best_stock(data):
fenge = data.items()
res = max(fenge,key = lambda jieguo:jieguo[1])
stock = res[0]
return stock
or in a lambda function
best_stock = lambda data:
More
The part 2 has the wrong interpretation of the lexicographic order. See [my new code](https://py.checkio.org/mission/determine-the-order/publications/Phil15/python-3/compare-deduce-choose-with-lexicographic-order/) to see the right one.
With `words = ['word', 'spread']`, the answer is `'spworead'`.
More
import re # ?
Consider use the maximum built-in function with the key parameter.
max(data.keys(), key = lambda x: data[x]) # this is doing the exact same thing as your code.
Or just
max(data, key = lambda x: data[x])
because it only look keys when read through a dict.
More
Shorter version
distance = lambda xA, yA, xB, yB: max(abs(xB - xA), abs(yB - yA))
def navigation(seaside):
coords = {elem: (i, j) for i, row in enumerate(seaside)
for j, elem in enumerate(row) if elem}
return sum(distance(*coords['Y'], *coords[
More
If you want print the path we take without a single change of **YOUR code**, you can use this decorator I did for fun. Just put
@print_maze_path
before the definition of YOUR function. (Your function can have more than one argument.)
def print_maze_path(f):
CHARACTERS = EMPTY, WALL
More
No need to put parenthesis around the thing to return, just `return result`, it's not a function.
if ...:
return ...
# else: # no need of else since return stop the function.
return ...
No need to make a list to sum elements
sum([next(n,depth+1,weight*m) for n,m in branch
More
There are other ways but I like the use of numpy, especially `reshape` and array of booleans. It's original.
More