49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 8 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.
We can do it in three lines without import math.hypot, but with complex numbers: a little less clear IMO.
grid = lambda N: ([i,j] for i in range(N) for j in range(N))
test = lambda i, j, probes: all(round(abs(i-x+(j-y)*1j)) == d for x,y,d in probes)
checkio = lambda previous: next(c for
More
abs(d1-d2).days #work so this too
return abs(date(*date1) - date(*date2)).days
# then eventually
days_diff = lambda date1, date2: abs(date(*date1) - date(*date2)).days
More
**Few explanations...** (I won't write a mathematical article for it)
_Mathematically:_ P is the transition matrix of the markov chain involved here.
_In english:_ P[i,j] is the probability to go to j from i with one dice roll.
M is the same thing as P with a ban on going through target.
**1/(I-
More
For those who think it is not a real 1-liner: imports can be made inline and "def return" can be made "lambda". Without sacrificing clarity.
aggregate_and_count = lambda iterable, Counter=__import__('collections').Counter, it=__import__('itertools'): Counter(it.chain.from_iterable(it.starmap(it
More
Even if you reinvent the wheel (it's not recommended like Veky said)...
Lines 6-8 can be one simple line:
ints[i], ints[i+1] = ints[i+1], ints[i]
And while loop should be a for loop here.
More
Same thing, shorter! Without test of enough letters, and a shorter last part. Not enough readable IMO, that's why I kept my code like it is.
from itertools import product
def hypercube(array, word='hypercube'):
coord_letters = {letter: [] for letter in word}
for i, row in en
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
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
First bravo you have done it, it was a long way to go...
Interesting. Lines 12-15.
Fight functions are too big IMO, I prefered put more logic in warrior class for simplify fights functions.
You can refactoring your code with **for example** replace all
any([isinstance(unit, Warlord) for unit
More
Hi!
Found that weird
marked = marked|set().union(*newly_marked)
# Instead I suggest
marked = marked.union(*newly_marked)
# or if update the set "marked" IN-PLACE is okay (I think it is) :
marked.update(*newly_marked)
and
indexed_circles = [(index, circle) for index, circ
More
No need of sum lists:
Counter(ring for cube in cubes for ring in sides(cube))
I did a sum at first too.
More
Well if `i != 0` then `i - 1 >= 0`
"1" if val == line[max(0, i - 1)] and i != 0 else "0"
str(int(i != 0 and val == line[i - 1]))
More
It's not 3rd party.
Plus
# You do not use the index i but a[i] and b[i].
def hamming(a, b):
return sum(s != t for s, t in zip(str(a), str(b)))
def is_doublet(numbers):
# something with zip too to avoid the use of "i".
More
def match(comp, test):
count = 0
# you do not use the index j but comp[j] and test[j]
for c, t in zip(comp, test):
if c == t:
count += 1
# "count == 2" is already True or False, return it
return count == 2
# or
def match
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
List/Dict comprehension is good
def convert(grid, points):
return {grid[i][j].lower(): (i,j) for i,j in points}
path = [(i, j) for i, row in enumerate(grid)
for j, cell in enumerate(row)
if cell.lower() == check[0]]
Your count variable is a li
More
First I don't see the point of pandas here (and it's a bit curious to me you can import it ^^).
Your DN you entirely write can be easier.
from string import digits, ascii_uppercase
DN[L] can be replaced by (digits+ascii_uppercase).index(L) (and then forgot DN)
You should consider learn li
More
I noticed that it's faster with `(speed + 1, speed, speed - 1)` than with `(speed - 1, speed, speed + 1)`. It makes sense: acceleration prefered to deceleration.
`0 < s <= end - pos` is shorter and equivalent to `pos < pos + s <= end` (new_pos is between pos and end).
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
return items == sorted(items) and len(set(items)) == len(items)
is really enough.
More