49
Phil15
30 56 64 Leader of the month
23054/ 25141
Last seen 18 minutes ago
Member for 6 years, 2 months, 22 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.

Best reviews / Newest reviews
methods contest-quarkov 9 3
I started timeit random tests before I see you already did it. But I test the current ten published functions (sometimes a bit changed). **1000 sentences from 1 to 100 words from 3 to 13 letters, tested 10000 times.** Functions are sorted in order to have decreasing performances. from timeit More
Three solutions + 1 in comments-Phil15 5 1
From another solution I "simplified", I would like to add a fourth one: ```python import functools as fn import numpy as np replace_first = fn.partial(np.roll, shift=-1) ``` More
filename.rpartition('.'), partial(sorted, key=...)-Phil15 3
@kudinov.feodor Well, a simple fix (keep separator in "name part"): def _sort_by_ext_key(filename): name, sep, ext = filename.rpartition('.') # assert sep in ('', '.') return (ext, name) if name else ('', sep + ext) More
For changed mission - Explained-Selindian 3 1
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
Always dreamt of using reduce :)-vit.aborigen 2 1
Reduce is useful to apply a function to a whole sequence so mult_two = lambda *args: reduce(mul, args) # is even more powerful without difficulty. mult_two(15, 6, 1991) mult_two(*range(1,6)) More
Dijkstra, heapq-kurosawa4434 2 1
I didn't know about `defaultdict(lambda: defaultdict(type))`, thanks. I thought about `defaultdict(defaultdict(type))` but that was wrong. More
First-24esun 2 1
An eventually dead unit_1 still wrongfully hits unit_2 line 21. Lucky it passed tests. More
1-liner: numpy determinant-Stensen 2 2
So `checkio = np.linalg.det`. lambda is not always needed. If you see other solutions with rounding methods, it's because the mission lately evolved. More
SymPy-flpo 2 1
We are all (except you) reinventing the wheel when sympy (and you) does it naturally. **+5** More
Lion in Cairo-veky 2 1
I did use yield from too but I prefered `yield from reversed(run)` to slicing making a copy. I quibble a little. =) More
Going up?-HeNeArKr 2
`range(len(items)-1)` is enough because `range(0)` and `range(-1)` are both empty. More
Third Newton-veky 2
I restarted this serie with your forum post. I thought about dataclass for weapons, not for warrior classes, it's interresting. More
Dynamic programming-Phil15 2
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
The Vampires-JimmyCarlos 2 1
Others units than Warrior are subclasses of Warrior, so you don't have to copy is_alive property each time, only one time in the Warrior class. If you think Army class like a list, consider (It wasn't my first idea but it's realy great) class Army(list): #Each instance of Army is a lis More
BFS limited by closest rook-BrianMcleod 2
For info, `next_enemy[int(not i)]` and `next_enemy[not i]` are equivalent. We have list[True] == list[1] and list[False] == list[0] It's because we have True == 1 and False == 0 More
Counter-kurosawa4434 1
map is usefull for simple mapping. For complicated ones, list/generator comprehension is more readable IMO, and no need of _import chain from itertools_ here with generator comprehension: return max(Counter(normalize(pos) for cube in cubes for pos in possib More
Need for Refactoring-von.Oak 1 1
You can define methods in your classes for simplify your code. Your fight function has become ugly from my perspective. Details of a specific unit "have to" be in the class of the specific unit. Imagine your fight function with an hundred of differents units. :-D It's only my opinion, I only make cl More
colin_the_defenders-colinmcnicholl 1 1
In a few number of missions, you will have 2 units with defense attribute. And an other attribute and..., and your fight will be hard do decipher even for yourself. Manage health can be done in warrior class (others are subclasses so no need to repeat the code). You can use hasattr function to know More
bin playing with truthtables-DeCooper 1
IMO, you should consider use join like messi = ''.join(str((int(x) and int(y))) for y in second) Doing that below, you create a new string s for each y in second, because strings are immutables. s = '' for y in second: s += 'something' More
First-mozurin 1 1
You can use the built-in function **max** instead of sorting the all dict just for look the first element. best_stock = lambda data: max(data.items(), key=lambda e: e[1])[0] More
1
2 3 4 5 6 7 8 9 10 11 12 13