57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 2 hours 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.
It seems really hard to write an O(n^2) algorithm for this mission, but you've managed that. ;-[
More
It would be an interesting idea to actually use `time.monotonic` for this. :-D
More
Yes, O(n) is nice. And of course, if the answer is True, then it's the best you can do. The question is, can you do better if the answer is False? :-]
More
You have a weird definition of elegant. :-] Sometimes a statement
if not text.endswith('.'): text += '.'
is better than appending a possibly empty string to text.
More
That loop hardly qualifies as math... you could have used recursion then. 🤓
More
You meant "Last: translate"? :-D ("First import, then split, then...":)
More
A nice idea, but it really can be solved much more Pythonically. At least you should factor out reversing the number.
More
I think you have confused The best number ever with The answer to life, universe and everything. :-P
More
> The list of banned words are as follows:
sum
import
for
while
reduce
Yeah, right. :-P
More
Of course, the len checking can be done in the same way, at the expense of blowing up the code by a factor of at least 2. But that's even more wrong than this. :-D
More
There are some weird things going on here. For example, I thought Python doesn't have a character type (different from str). I bet you thought so too. Yet look at line 20.
Calling ord('aa') raises TypeError, calling ord('a') doesn't, but they are of the same type. It seems Guido didn't really mean
More
Ah, yes, the "sugrically removed recursion" solution. :-D But still, it's nice that you converted it to BFS (queue) instead of the obvious DFS (stack) one.
(Not more than 3+ because you're too anxious about types. In a duck-typed language, it is mostly just nuisance.)
More
Why + ".*"? Really no reason for that.
And of course, "in" works perfectly fine with str. No need to import heavy machinery of re.
More
You don't need parens around lambda: lambda is it's own left paren. :-)
opt is a weird name (I think you're again calling it by implementation, not by meaning;). `cmp` would probably be better (in Py2 a very similar argument was really called `cmp`).
In fact, name `inner` has the same problem. "ex
More
You might love Python, but you obviously hate me. I see what you're doing, but I don't see what you're trying to accomplish. It's probably so obvious to you that you didn't even consider the possibility your motive wouldn't be understood.
Can you articulate your message? Even terrorists make some k
More
Line 9 surely shows some misunderstanding of how Python works. What did you think it does (as opposed to just "return data_new")?
And of course, you can just write a list comprehension.
return [x for x in data if cnt[x] > 1]
More
This is a perfect example of how deeply unpythonic regexes are. That line 6 seems like it has fallen from some wholly different planet (named Perl, incidentally:).
BTW,
sum(regex.match(element) and not re.search('\d+', element)
for element in re.split('\W+', text.lower()))
More