57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 14 hours ago
Member for 11 years, 6 months, 6 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.
First, a defaultdict would _really_ help here. :-)
Second, you don't need () inside [] indexing. Just d[i, j].
Third, end of line 11 can be just `... else max((n1, s1), (n2, s2))`. Tuples compare sensibly. :-)
And fourth, you can get by without tracking lengths all the time, just calculate when n
More
Yes, this is much nicer.
That ugly last line indexing, it could have been just d[max(d)], right? :-)
More
Not boring at all. That [Chekhov's product](https://en.wikipedia.org/wiki/Chekhov's_gun) in first line is very interesting. I deeply wonder what was its intended purpose in the never-revealed third line. :-DD
More
... if array ... is much better than ... if len(array). If you really want to use len(array), you can use and. :-)
len(array) and sum(...)*...
More
... except if array is empty, then it cannot. ;-D
More
Please don't use find if you just want to see whether something is _in_ something else.
if a.find(b) >= 0: ~~~~> if b in a:
Also, sum is a builtin. You can use it directly instead of rewriting it. ;-)
return sum(word in text for word in words)
More
Too many "list"s (in cols).
You don't need () around '\_\_\_' in lines.
You don't need 0 and 9 (len) in slices: inline[::4].
If you're really obsessed with speed, try inlining diags and cols. Also try extending rows directly instead of copying.
More
Nice. Could be a bit simpler if you pulled int conversion into iteration itself:
for digit in map(int, str(number)):
if digit:
result *= digit
And use *= and similar assignments... they do make code easier to read.
---
A minor philosophical point: "result" would probably
More
Line 4 is a perfect example of what horribilities people go through, just to avoid writing another newline. It's not worth it. :-P
digit = int(i)
if digit:
s *= digit
More
Line 1 is unnecessary in principle, but even if this were Python2, it would still be unnecessary, since it specifies the coding of _source text_, and there you don't have any funny characters. :-)
BTW that three-char indent really stabs the eye. ;-P
More
Use // for int division, much more readable than int(/). You can also use divmod since you need both size % 2 and size // 2. And eliminate duplication, there's no need to write med calculation twice.
You can also use if...else expression, but it's not necessary. And a wizard would use `data[med] +
More
First, read about `collections.Counter`. It will make your life a lot easier.
Second, `dict()` is `{}`. But you probably knew that. :-)
Third, drop [] inside (). They are just slowing you and Python down. `sorted(k for ...)`.
And fourth, `sorted(blah)[0]` is really more readable and more efficien
More
count\_diff is very nonclear IMO. :-P Much simpler would be to do what the name says, instead of complement\_of\_count\_eq :-P
sum(f != s for f, s in ...)
\+ what nickie said. Python list is really an array, but that precisely means that pop(0) is O(n). deque is what you need (or better a
More
Nice contortions you're going through just to get it all in one line. I even learned something (locals can't be changed live, but function dicts are fair game:). It can be made much shorter if you want, though. For example, e[0] if e[1]==k else e[1] can be written as e[e[0]==k]. Also, {e for e in E
More
* About that htoi function: int accepts second argument as base. htoi(a) is in fact int(a,16). revsum can also be written using it, you just have to reverse the string: int(a[1::-1],16) Line 44 could also use revsum, right?
* That while loop instead of for is really jarring. And its body could mu
More
Meh... I expected more of you (for example, calculating probability distributions, and guessing most probable things:).
BTW, it's surprising you don't use chaining:
0 <= i < N
it really is more readable (at least Guido thinks so:).
Nice check if field is empty. :-)
If neighbors we
More
LOL, this is actually an interesting one. I'd even give it a few thumbs if you change the category. :-P
More