57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 15 hours ago
Member for 11 years, 6 months, 24 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.
A cool and very hard exercise: what is the maximum recursion depth this solution can have, given the preconditions of the task? :->
More
You know that this isn't really speedy? nlogn, same as sorting.
More
First we take Manhattan. Then we take whichever is smaller of East Berlin and West Berlin...
🤣🤣
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
You can chain comparisons.
if number % 3 == number % 5 == 0:
Nice to know but not really needed: you can use not % without parentheses (as opposed to C).
if not number % 3:
More
_Why_ did you think you needed line 2? You Py2 folks are so obsessed with lists, it blows my mind. :-D
Also, line 4 is just "if args:".
And you don't need () after return.
More
Ok, but that prints are cluttering your code. It's ok for debugging, but remove them before publishing.
More
Line 10 is really interesting. Remember, "special cases aren't special enough".
What could "".join([]) do, except give empty string? Why do you think it's a special case?
Line 7: of course, there is .isupper(). But if you really need "ABCDEFGHIJKLMNOPQRSTUVWXYZ", you can use string.ascii_uppercase
More
Line 4 should be removed, and once you remove it, you see that you don't need line 3 either. Just say
for word in words.split():
(don't you think "word" is nicer name than "item", for something that iterates through "words"?:)
"!= True": ugly. Python has a "not" keyword. Or you can reverse lo
More
https://www.youtube.com/watch?v=o9pEzgHorH0
There is really no reason for a class here.
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
"<=1" is a cute and completely unnecessary "optimization", that's really hard to grasp at first. You could just say "if not args" in line 2 (or "if args" and reverse returns). In newer Pythons, you can also put default kwarg in min and max, eliminating the need for if totally.
BTW you don't need *
More
That "print( c )" wasn't very helpful, right? :-)
In fact, your steps can be much more pythonic.
b = words.split()
c = ("10"[x.isnumeric()] for x in b)
d = "".join(c)
return "1"*3 in d
Whenever you're mapping lambda, you should use a generator.
map(lambda arg: expr, seq) ~~>
More