57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 23 hours ago
Member for 11 years, 6 months, 24 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.
Much more pythonic is:
def checkio(data):
try:
return data[0] + checkio(data[1:])
except IndexError:
return 0
EAFP. ;-)
More
Nice and straightforward. But Dijkstra is massive overkill. The point is, there are only two paths (+ degenerate case) you have to explore. See my solution, I can write it in long form if you need.
More
Cool, but could be better.
[blah, blah] if cond else [] ~~~> [blah, blah] * cond
And those three `n`s should really have three different names. `h`, `t` and `o`, if nothing else. :-)
More
Nice UF. But of course you don't need a class.
Line 44: You don't need `list()`. In fact you don't need `set()` either. ;-]
Line 45: `sorted(eggs, key=spam)[-1]` is also known as `max(eggs, key=spam)`. Timsort _is_ damn fast, but max is linear. :-)
Line 19: see `dict.fromkeys`. Very useful and fe
More
Bresenham is cool, but overkill. You just need to see if a line intersects any of the four edges. That can be done with classical "signed triangle areas" algorithm.
(Of course, in my algorithm A* is overkill (Dijkstra is fine, as you show), but my A* is universal - I have used it unchanged on at
More
This should be fast enough for you performance fetishists. :-P
Explanation of a title, since I've seen many people not get the point of my titles:
Besides hopping as a toad from state to state, this is also ugly as one. :-P
Also see the `)):` in line 33. Python is very sad. :-(
More
.replace('0', '1') is really a hack. :-) If you want to be clear, if (or filter) would be better.
Also, total is a strange name for a product. ;-)
More
Nice. BTW, there are set literals in Python: set([first, second]) -> {first, second}.
More
int(round(bla,0)) is just round(bla).
Also, see "Always use a def statement instead of an assignment statement that binds a lambda expression directly to a name." (new version of PEP8).
Otherwise, nice solution.
More
re is obviously an overkill here. With the necessary escaping it is even longer than ordinary index (or my approach:). And you don't even use IGNORECASE.
Nice use of bisect.insort. :-)
That ugly offset calculating can be completely removed, if only you replace "enumerate" with "reversed" in li
More
Nice, but can be compressed much further. First, you don't need twice as long items in ALPHABETS, just say text.upper() at end of line 4.
Second, once you know that only \w are in your words (and BTW you don't need []s), you only need one item in ALPHABETS, another one can be deduced with [A-Z] a
More
This is a nice example of how chaining can help you write better code.
First, x == 1 and y == 1 can be written as x == y == 1.
Then you see you have it also in equivalence.
if x == y == 1 or x == y == 0:
Then you see you can factor out x == y.
if x == y in (0, 1):
Then you realize that
More
Why [0]? There is no char in Python, just str of len 1. Just as there is no "digit", just a single-digit int. :-)
And don't aggregate over listcomps. Drop the [] inside .join().
More
For a beginner, it's pretty smart. ;-) But...
blah if cond else 0 ~~~> blah * cond
That's exactly what multiplication with bool does.
More importantly, `words = words.split()` has no advantages (over just `for word in words.split()`) and many disadvantages.
First, by rebinding the name
More
Don't separate : by a space on the left ("else :"). It might look cute, but almost nobody else does that. Try to be more consistent with those spaces all in all (line 6).
== can be chained: number % 3 == number % 5 == 0
You don't need result: you can just return whatever you want when you want, yo
More
If you don't want to be boring, you can always look at the @StefanPochmann's solution. ;-)
More
Nice handling of empty stack. :-) But the end is just
return not stack
More