57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 15 hours ago
Member for 11 years, 6 months, 23 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.
`x` is a _terrible_ name for an element of `NEIGHBORS`. It is most usually used for _one_ coordinate of it.
for dx, dy in NEIGHBORS:
x, y = col + dx, row + dy
(Of course, this is much better expressed with complex numbers, but here it is an overkill.:)
And (pun intended:) then the nes
More
Here we see how `dict` is really much nicer (functional) way of expressing a switch. Of course, inner `if`s can be written as expressions (or tuples indexed by bool), even if you don't write them as normal algebraic operations.
return dict(
conjunction = 0 if not x or not y else 1,
More
This is really nicely written considering atrocities you've written before ;-) (the only thing I'd change is write lines 9~11 as
other = pair.split("-").remove(node).pop()
, and maybe write initializers together
visited, current = [first], {first}
).
More
Golden rule of Python iterating: **iterate through what you need in the loop suite**.
If you need just the elements of a sequence, don't iterate through its indices.
If you need both (elements and indices), again don't iterate through just indices: use `enumerate` to iterate through both.
If you
More
`pawns_indexes` is a terrible name. Those are not indexes, in any sense. `pawns_positions` would be much better. Or just `positions`.
In line 10 you use destructuring `for`. You really should have used it in line 4 too:
for y, x in pawns:
positions.add((int(x) - 1, ord(y) - ord("a")))
More
Look at [this](https://docs.python.org/3.5/library/collections.html#collections.Counter). Python has got you covered. :-)
More
"square" is a very strange name for list of functions, don't you think? :-O
More
Horrible. :-P
First, why those empty lines? They don't increase readability, especially since one of lines is too long.
sum([... for ...]) ~~~> sum(... for ...)
Just drop the []. Generator expressions are nicer, clearer, faster, and use less memory.
And you surely don't need list compr
More
Nice algo. A few Pythonic nitpickings:
* It would be nicer if tuples in q were (time, pos,...), then you could just sort them directly by time. Or if you want to be explicit, you could have used namedtuple.
* q.pop(0) is slow with no good reason to use it. It would be better to q.sort(reverse=True
More
Of course, another view at the [current top solution](http://www.checkio.org/mission/striped-words/publications/RRRQ/python-3/first/).
More
It always bugged me why people import the wrong thing from collections. :-) Counter is obviously more specific, and precisely what you need.
And don't map literal lambdas, especially of one variable. You get precisely nothing.
sum(map(lambda arg: expr, seq)) ~~~> sum(expr for arg in seq)
More
Not fancy or efficient, I agree. Simple to understand... well.
Horrible duplications, indexing instead of unpacking and naming things, superfluous constructs, unnecessary rebindings... and to top it all off,
if adict.get(key, False):
:-O Even Py2 should have `key in adict` construct by now.
More
I hope you're sarcastic with the title. :-P
First, "m" means precisely nothing. Just return it.
What's that for doing there??
-1 >= can be more simply written as >. Those are ints.
More
Beginners are strange. Beginners like you, even stranger. :-DD
Anyway, to make it easy to understand also for us poor gurus over here, you could:
* remove that trunc, it serves no purpose
* remove that list from line 2. It makes no sense to listify it, if the only thing you're going to do with it
More
It seems I'm not the only one getting strange compliments on CiO. Python gets them too. :-D
More
I'm not absolutely sure, but I think Py2 also gives you better way of calling replace:
','.join(phrases).replace("right", "left")
More
Lines 5 and 7:
if i in "([{":
if i in ")]}":
Line 15: You can just
return not stack and not error
Or even `not (stack and error)` :-) But really, why error at all? It's not that you can recover anyway. When you find an error, don't set error to True, just `return False`. At the end,
More
Feedback? Too much duplication and too much low-level code.
About that uglier-than-toad line 6... if you want to be a wizard, read http://code.activestate.com/recipes/204297-the-secret-name-of-list-comprehensions/. If you don't, just write the loop like normal people. It's not hard. :-)
More