57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 42 minutes ago
Member for 11 years, 6 months, 8 days
Difficulty Advanced
We shall not cease from exploration, and the end of all our exploring will be to arrive where we started and know the place for the first time.
Instead of returning [], you should return None. That is, just delete lines 4 and 5.
def outcome((a, b, c)):
if a == b == c != '.':
return a
Why do you turn everything into a list? For example, line 9 is completely unnecessary. Not to mention that the whole first part is un
More
Line 8: [] is a strange name for a set. That's the main problem with your comments anyway: they are incredibly misleading sometimes. You probably come from some programming language where it is much more important to explain things to compiler than to the human reader. In Python it's the opposite: i
More
Line 10: horrible. Refactoring? "Extract variable"?
move = lambda t, d: chr(ord(t) + d)
for x, y in pawns:
up = move(y, -1)
if {move(x, 1) + up, move(x, -1) + up} & pawns:
count += 1
More
You don't need "+" in your regexen (you even don't have it in the first one:). And you don't need r here, though maybe it is good to always write it to remind you of regex parsing. But the last one then really ought to be \d. ;-)
Also, you don't need bool around the first condition, and even on the
More
Nice reorganization into tens and dups, but the code has some horrible duplication. You can do much better. ;-]
Here is an interesting approach, that tries to stay faithful to your algorithm. Of course, if you're willing to depart a little from your original algo, you'll be able to write much bette
More
ROTFL. This made my day. :-)
An idea for a new module: rmath. When we have math and cmath... :-DD
(BTW have you seen my "determinant" solution?:)
More
Too complicated and ad hoc. BTW you don't need () around num%3 and num%5.
More
Nice idea, but you really could just break instead of += 'N'. It doesn't really have a purpose. :-)
More
Don't artificially single-exit your functions. This is not Pascal. It gets you nothing and you clutter the code.
More
Again you're writing comments instead of code, misunderstanding the main purpose of Python. For example, line 34. Why is it there?? Wasn't it more to the point to write
chr(most_frequent + ord('a'))
or, in fact much better,
LETTERS.lower()[most_frequent]
Those doctests are cute, but a bi
More
Line 23: never index by index. Pythonic way is to index a dict.
"not len(stack)" is simply "not stack" (twice). And in line 18 it can be reversed for greater clarity.
Many of these comments are either completely redundant (like line 8), terminologically wrong (like line 5, Python term is a "sequen
More
Those "names" don't really help, if you must break the 80col boundary. sorted\_data is just one char shorter than sorted(data), and semantically completely empty, while "list\_length" is such a bad name that it should be taken outside and shot. :-P
More
Well, this is my solution, so I don't know if it is ok to vote on it. It's just an ordinary topological sort, with lexicographic (native) tie breaks. Nothing fancy.
More
Essentially the same solution as mine. [0 for _ in range(w)] is simpler written as [0]*w (or better yet, you can use a defaultdict:).
But how did you know that x coordinates are integers before I asked that in the comments? Just hoping? :-)
More
Very complicated and not very pythonic (things like
cpt=0
for i in range(N):
cpt+=(visible[i]==True)
return cpt
really hurt). And I don't really get what those averages of X and Z are for. French comments don't help either. :-(
More
Very unclear, riddled with useless special cases, and not using Pythonic idioms.
More