57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 1 day 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.
Condition in line 7 is really strange. What is it doing there??
Also, int(round(blah, 0)) is just round(blah).
And if you really use Py3, those / are truedivs. Don't write -2.0, write just -2. (Or better yet, cancel -1 and use 2.:)
More
Clear?? Hm... classifying commands according to len? And checking "if letters != []" instead of just "if letters"? No, sorry. Not clear. ;-P
More
That's one horrible code duplication. But more importantly, it doesn't work, does it?
verify_anagrams("a", "ab")
More
Lines 1 and 2: LOL. :-) Sometimes it is easier to just bite the bullet and write what you really mean.
parens = {"(":")", "[":"]", "{":"}"}
You could have simplified line 12 by putting one lion in Cairo first (see my solution and respective comments for explanation;).
More
If you really wanted to be _clear_, you'd probably use .count('1') as before. ;-] n &= n - 1 is a nice trick, but not really "clear" IMO.
More
Aaaargh. Too complicated for my poor eyes. :-/ "== True", why? And Lines 10~11, why not just [i]? And why not use a real dict, with setdefault instead of that checking all the time?
Or better yet, just use a collections.Counter. Or even better, use builtin max with custom key. ;-P
Detail: at the e
More
First, list is unnecessary. "for entry in expression" works fine.
brackets can also be a str, then you can just brackets += entry in line 7. (Yes, it's slower, but not much, and later code becomes _much_ simpler.)
Line 6: if entry in "([{".
Lines 11~17 (and twice more):
if brackets.endswith(
More
Really? re.match with literal? How about just "PUSH" in entry?
Lines 11, 12 and 13 are just if m. But really, use a .split and be done with it. Or even a slice if you feel dirty. ;-) int(entry[5:])
Also, lines 18 and 23 are just if stack.
Lines 19~20: del is cool if you don't need that value. If
More
This is _incorrect_! asin gives values up to pi/2, but angle\_b can of course be obtuse. Write a function for how you calculated angle_c, and apply it three times. Also, math.degrees could come handy. ;-)
More
Yes, you should have used a dict. (Rule of thumb: if it would be an ordinary switch (with breaks after every case) in C, it is not if/elsif/elsif/else in Python. It is (probably) a dict. If it is too complicated for a dict (code differs, not only data), then it is a class. But it's almost never a bu
More
If you're really using EAFP, then you don't need ifs. You be bold.
assert r >= 0 <= c
...
except (IndexError, AssertionError): pass
If you really use EANP (it's easier to ask nothing than permission:), as here, you might find contextlib.suppressed context manager useful.
Line 9: t
More
collections.Counter might be nice.
And code duplication should be eliminated. Make a function, and call it on rows and columns separately.
More
Decorate-min-undecorate is out of fashion. min (or better here, max) has a key argument for that purpose exactly.
And again, for c in text.lower() is better than rebinding text. (And why sorted??)
More
Without lambda, it would be even greater justice. :-P Just remove all "lambda x, y:", and (x,y) at the end.
More
Wouldn't code be _much_ simpler if you had
FIRST_TWENTY = [""] + FIRST_TEN + SECOND_TEN
TENS = [None, None] + OTHER_TENS
? :-)
More