49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 38 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 talked about zip, usefull here to have columns. (there is a little thing to do before)
If you have to count something, use a tool doing it for you. Like str/list/tuple.count( ... )
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
Given a list of moves _L_, the sequence
(stones(n, L) for n>=0)
is eventually periodic (and very often periodic), and the period depends only on _L_.
Unfortunately, compute this period is not really simple in general. But with it, we can compute _stones(n, L)_ easily for **very large** numb
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
else after a for loop? I know the thing but useless here.
No need of continue with "!=" test.
if matrix[i][j] != -matrix[j][i]:
return False
Well, then, you should considerate the use of "all(...)"
all(matrix[i][j] == -matrix[j][i] for i in range(len(matrix))
More
List comprehension is so... so good...
t = [[- matrix[j][i] for j in p] for i in p]
Then "matrix == t" is already the boolean you want return.
return matrix == t
Finally,
def checkio(matrix):
p = range(len(matrix))
return matrix == [[- matrix[j][i] for j in p] for i i
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 seems complicated. But probably clever "sweep line algorithm". Do you think this work for rectangles with float coordinates? Because int coordinates is a big simplification for this problem.
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
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
`if res[i] != True` then `res[i]` is already `False`. so lines 7 - 11 can be much shorter. Plus two pythonic changes:
def stones(pile, moves):
res = [True] + pile * [False]
for i in range(1, len(res)):
for j in moves:
if i - j > 0 and not res[i - j]:
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
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
No need of sum lists:
Counter(ring for cube in cubes for ring in sides(cube))
I did a sum at first too.
More