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.
Last line is just
return s*(n == 1)
And yes, you could have get rid of that special case (given your hate for special cases) in line 2. For example,
return (s + (not s))*(n == 1)
Here you do need parentheses around not, since it is special in grammar. But "not" being special enab
More
Again, no parentheses around "not s" are needed. You never need them when you use it as a logical condition, only as an arithmetical expression.
BTW sentinel really could have helped here (to reduce number of cases:). See mine. ;-)
More
Line 3: nice optimization, but it's not like we have millions of elements. list.index would work perfectly fine. :-)
Line 5: str is also just a (kindof) list of characters. "qria" is probably more readable than ["q", "r", "i", "a"].
Lines 37~40: you _should_ feel bad. Not because of hardcoding
More
So, you see the problem? How can using str.endswith (which is intended for exactly this kind of check) not be clear, and at the same time using
c.split(d)[-1]==""
is somehow "clear"?
Everybody considers their code clear. That's why this whole category thing is nonsense.
More
Sorry, *= max( , 1) is very unclear to me.
But this is obviously ridiculous. Everybody considers their own code clear.
More
Cool. Mine is also floatless, but in a much more boring way. :-D
BTW, all these
expr if decimals else 0
are just
expr*bool(decimals)
More
pi is also in cmath (and has the same value:), no need to import it from math separately. :-)
More
You don't need outer parentheses in return. :-)
Also,
al, bl = map(int.bit_length, (a, b))
would probably be nicer (less duplication).
More
Disappointed! :-P
I expected at least you to see that all of these cases are just instances of a general formula. :-]
More
Please don't use "concatenating digits in a large base" as a method for selecting by multiple keys. Unicode has more than 1e5 code points (if not now, then soon:)). Tuples comparison is exactly meant for this. Key should be (count, -ord).
Also, this algorithm has quadratic complexity, while the t
More
Nice and complicated. :-P Wouldn't dict be more appropriate data structure for z?
More
First, if you _used_ regex here, that would be remarkable. Not using Python re here is like not using a bicycle for swimming. :-D
Second, argh. Please don't do
if c: return True
else: return False
if c binds something bool. Do
return c
Token count just went from 7 to 2. A
More
Yep, a lot more code than needed. BTW you get a Special Confusion Award for using " ".join on a str. :-D (And then .split() right after that.:)
More
A lot of people know about .format _method_, but they don't know about format _function_. It's really much nicer when you just want to format a single value.
format(m ^ n, "b")
More
First, don't test "len(args) == 0". Just test "args" (or "not args", if you want to have that order of returns). PEP8: "For sequences, (strings, lists, tuples), use the fact that empty sequences are false."
Second, why sort? min and max are linear.
More