49
Awesome Team
Philippe Cholet
https://github.com/Philippe-Cholet
Last seen 3 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.
First, great job you did it!! It was though, right? I hope you enjoyed it :-)
Line 137, I would have write except AssertionError instead of catching every exception? Maybe it catch the exceptions you raise too? I would have do this
class SolverError(Exception): pass
# then
raise Solver
More
I would say this is more creative than clear (for merger and last line) but it's great that you do the job with 7 lines.
More
Wow, more than three hundred lines of code/comments before my checker function. Impressive.
I hope you enjoyed it enough! It's not that obvious, looking at it ^^
I don't have the courage to read it right now but I will try someday. Right now, I only have the keywords: constraints, backtracking, OO
More
Great job, you did it!! :-)
Yeah, copy huge things or very often is time consuming.
Naive DFS is not really possible here. It can be interesting but only for small searches.
I'm not sure reading your code: are you using arrows in both ways? (if my question is clear enough...) Or can you explicit
More
There is, hopefully, another way to guarantee that without sorting the entire set, your key function just have to be more precise, with lexicographic order.
lambda x: (abs(x-target), x)
More
You told me that your solution is slower than mine (absolutely no shame in that, you solved it and it was definitely not a moderate mission, right?). I didn't read all your code but it seems you use `deepcopy` a lot, I can bet it takes you some time. my code don't do any copy of anything (well, ther
More
Private messages could be useful. You removed your entire forum post, not just the last comment. So I don't really have a proper way to contact you.
I see where is your mistake, your justified lines ends with whitespaces. Otherwise, it's good and can pass all tests.
This message will be removed af
More
It's because you can access builtins (thanks to `vars()`) as a dict and not as a module like it should be, so this would not work outside checkio editor. Maybe I should have forbidden divmod function in builtins. (I suppose it calls it somehow, it's hard to decode with vowels replaced by "a".)
Then
More
`lambda x: str.strip(x)` is the same as `str.strip`, just more complicated.
Comments this way seems unusual to me: `# Currenlty, only ``int`` is considered.` for example.
More
Great job with numpy! Even if I prefer my way with complex numbers. `cmath` module could do a part of the job for you. And there is probably a way to do graham stuff with complexes.
`a[randint(0, len(a) - 1)]` or `choice(a)` (from random too).
`del sorted_pts[...]`, not `sorted_pts.pop(...)` ?
More
`roots` could be a list instead of a dict. More importantly, since you only need the last element in roots, root could be the last element.
roots = [(1, w_count, b_count)]
for _ in range(1, step + 1): # don't need n variable anymore
nlist = []
for root in ro
More
# line 8
type(tree[0]) is str or type(tree[0]) is int
# or
isinstance(tree[0], (str, int))
# line 19
[x for x in iterate(tree)]
# or
list(iterate(tree))
# line 27
tree = False
# or just
break
# since it does the does the same thing in a clear way
More
for subtree in tree[1]:
if result := find_node(subtree, node): # python 3.8+
return result
# No need to return None, it returns None when it does not encounter any return statement.
You call `find_node` a lot. Hopefully I did not provide too big trees in random tests.
More
I'm not sure I would call it clear, but I like the way your getter/setter functions manage multiple arguments, and the use of `reduce` I think.
More
`min` has a default parameter that can be useful. And `len` is great function on its own.
min(variants, key=lambda x: len(x)) if variants else False
min(variants, key=len, default=False)
More
Sum comprehension is great.
def is_adjacent(i, j):
'''Return true if x and y differ by one digit, false otherwise'''
return sum(i_digit != j_digit
for i_digit, j_digit in zip(str(i), str(j)))
Great job!
More
`0 if m==n else 1` or just `m != n`. Booleans are integers 0 and 1, so we can sum them.
More
No need to have sets. ranges are enough. Test if a number is in a range is fast too.
More
Just in case you don't know
from collections import defaultdict
graph = defaultdict(list)
# then
graph[num1].append(num2)
# instead of
graph[num1] = graph.get(num1,[]) + [num2]
Or without collections module
graph.setdefault(num1, []).append(num2)
More
About `[[]] * rows`, be careful.
>>> L = [[]] * 5
>>> L[0].append(1)
>>> L
[[1], [1], [1], [1], [1]]
# Same object five times.
More