57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 3 hours ago
Member for 11 years, 6 months, 7 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.
You again with your rebinding. Here it is forgivable, but really, the whole thing is just
"".join(phrases).replace(blah)
Dots are done from left to right. It's as if you wrote
b = a + b instead of return a + b + c
return b + c
More
Giving one-letter names to objects used only once does _not_ make your code more readable.
abs(date(*date1) - date(*date2)).days
The only thing you've achieved is making the reader go up and down your code, wondering what the heck is `f`. People _do_ read primarily horizontally, despite heavy
More
`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
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
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
Lines 4~7: Again, don't know about Py2, but you probably have .partition. Use that instead of .split, it fits much better.
cmd, _, arg = i.partition(" ")
For the other try (lines 8, 11 and 12): Yes, EAFP is nice, but sometimes it pays to be practical:
if cmd == "POP" and stack: stack.pop(
More
Well, you said everything about ghastliness... so I won't go there. I'll just say that number of cases being finite is not an excuse to go haphazardly enumerating them. :-)
But a more important lesson about how Python namespacing works: you `import` _names_, not objects. Conclusion: you don't need
More
There are many weird things in your code, but I'll ask just this: why are you stringifying your keys? `si` returns a tuple of floats, which is perfectly usable as a key.
More
It's ok, but if you use cmath, you'll see that there are no different cases. :-)
Also, why name something `r` (an empty name, probably for "value to **r**eturn") just to return it immediately afterwards. Especially at the end... just
return [round(func(a, c), 2) for func in (v, sa)]
But of co
More
Your code has a weird mix of using //2, /2 and /2.0. (That's probably the consequence of using Py2.:) Either stay with Py2 (without `from __future__ import division`), use `/2` and `/2.0`, or (much better;) switch to Py3, where you use `//2` and `/2`.
Also, length should be properly spelled. Or jus
More