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.
Since people have asked me how would I write the same solution if I was writing professionally, here it is: http://pep8online.com/share/51fc1a526cee1659c2a34a0f
You can probably see that the algorithm is completely the same. The only thing that's different is documentation (annotations, variable
More
LOL @ `reverse=False` part. :-) You know False is default here, right?
More
Aargh. Too many cases. My head hurts. :-/
Many of these conditions can be checked mathematically instead of constructing lists and checking containment. E.g. line 31: "if not number % 100:"
str_number[1]+str_number[2] is just str_number[1:3]. Or use "slice twice": str_number[1:][:2] (from inde
More
I put those chars @StefanPochmann generously provided me to good use - traded them for spaces at a favorable exchange rate. :-D
[Of course, now someone will make a 'vfn' solution without spaces. But that's just too predictable.:]
More
Your spaces are a bit inconsistent. At least put space after `*=` if you put it before.
Also, if you `int(n)` before, it would be easier to write a condition:
d = int(n)
if d:
result *= d
More
> Python is cool :)
You have no idea. :-D
First, you don't have to write your uppercase. Just
from string import ascii_uppercase
Also, that if can be much better placed _after_ for. Then you don't need singular else.
''.join(ch for ch in text if ch in ascii_uppercase)
And of course, th
More
BASE.find(str_number[i]) really could be factored out.
Instead of that ugly index manipulations, you can use enumerate (and possibly reversed).
More
`if len(args) > 0` is unpythonic. Just use `if args`.
Or, if you really want to use len(args), use it interestingly:
len(args) and max(args) - min(args)
;-)
More
:-) If you're going to use `len() and`, you can use it in at least two other missions. Try to find them. ;-]
More
As I said already, drop [] inside (). You don't want to make a list just to ",".join it. You just want to ",".join values in order.
More
You're reinventing [the wheel](https://docs.python.org/3.9/library/heapq.html#heapq.nlargest).
More
Nice idea, but really too complicated implementation. See:
checkio=lambda t:3*"True"in"".join(str(w.isalpha())for w in t.split())
More
Yeah, preparing the grid into a graph for Dijkstra is a lot of work. It can be shortened somewhat by factoring those things that are repeated for all four cardinal directions, but it's not easy.
In most places where you can use a tuple, you can also use a list, which helps when it is a 1-tuple, for
More
Why all these conversions tuple -> list -> tuple ?? Just have a list if you intend to mutate it.
More
Line 1 expression can just be "secs // 60 + (secs % 60 > 0)". bool _is_ int. ;-)
That antipattern in lines 10~13 really should have been using collections.Counter. Learn about it, you'll love it. ;-)
Lines 16~19 are _precisely_ the reason why Guido finally added conditional expressions to Pyth
More
When a loop has 4 lines, one of which is "continue", that's surely an overkill. :-)
"if word != w and word.endswith(w):" is obvious solution. "for w in dic - {word}:" is a clever one. ;-)
More
Wow. Until now, I thought you came from Perl land, but now I'm not so sure. Very few of these people know about accumulator recursions. :-)
More
`not x>y` is `x<=y`, and `not x==y` is `x!=y`, right? :-)
Python's switch is usually not a huge if chain. It is a dict.
dict(
conjunction = x and y,
disjunction = x or y,
...
)[operation]
More
Khm. No need to enumerate the whole square when you just need the upper triangle. Slice it, man. :-)
for late_index, late_val in enumerate(sequence):
for early_val in sequence[:late_index]:
res += early_val > late_val
`res` would probably profit from being called `inversion
More