57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 21 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.
If you're wondering how people wrote that pattern before walrus, check out my other solution. ;-)
More
That loop hardly qualifies as math... you could have used recursion then. 🤓
More
You should use the Smart Split (without an argument). That way you don't need `if array else []`.
More
It can be even clearer [without them](https://py.checkio.org/mission/boolean-algebra/publications/veky/python-3/an-operator-by-any-other-name/). :-]
More
This is a beautiful algorithm. Too bad it's written in Java, not Python. :-P :-D
More
There really is no reason for observers being a list: a set is much more appropriate.
More
Instead of +1, you could have used the second argument of sum.
And instead of that ord business, you could have just sum the bytes. ;-) [See the "Happy New Year" thread on the Forum for details.]
More
Question: which galaxy? ;-)
(Hint: "a long, long time ago" is precisely 39 years ago;)
More
A cool and very hard exercise: what is the maximum recursion depth this solution can have, given the preconditions of the task? :->
More
An interesting question: why are parentheses needed?
A more interesting question: were they needed in all previous versions of Python? ;-)
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
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