57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 13 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.
You're reinventing the wheel. See Counter in collections module (standard library).
More
If you're trying to see how it works: just print(r) between lines 5 and 6. I'm sure you'll see what r is, and then the rest is pretty obvious. (Of course, if there are any questions, just ask.)
More
This is just to show various methods your system can be cheated. Fix these, and I'll find new ones. :-P
More
If you like using external stuff, those little lambdas are already there:
change "lambda x, y: y/abs(y) * x" to "math.copysign"
change "lambda x, y: x * y" to "operator.mul"
Batteries included. ;-)
More
LOL. This is the reason why I don't comment my code. :-] There would be more comments than code. :-)
More
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
Your idea of "functional programming" is very strange. Hint: lambdas and foldrs are not everything. :-D
See math.hypot, operator.and_, itertools.product, and itertools.starmap. And sorted returns a list already - what did you think, it will return an iterator? :-]
More
Yes, that's the way (a-ha, a-ha,) I like it (a-ha, a-ha). :-D
As a nitpick, I think that manual for-loop could be automatized (written as a real for loop), with while inside to repeat a single pass until d<0. But this is probably ok too.
More
A nice variant of my "Ordered" solution. :-) Is there _any_ reason to use d << 1 instead of d*2 (or even nicer, d+d :)? You just need parentheses for it.
BTW, in Py3.4, max finally got a "default" argument (despite Raymond's cries:), so you don't need that ugly line 4. :-]
More
Nice complex key. :-D But you don't have to search through the whole text, just through a..z. :-)
More
Awww, iter, finditer, and even _itertools.chain.from\_iterable_. Awww. :-D
Haven't you buried the idea of your solution a bit too deep? :-]
More