57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 12 hours ago
Member for 11 years, 6 months, 12 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.
At first sight, this is usual high-order functional stuff. But there are a few puzzling details, in the form of code that should do nothing, but without it, the solution doesn't work. :-]
* Why is that "if (push, pop, peek)" there? 3-tuple should always be true, right?
* Why is that "and (yiel
More
Wow! A surprisingly algebraic (for you) approach. :-D
One of those `image`s is really a `preimage`, right? :-) Also, `relation` deserves a better name. Though I don't know what it is. :-/ `precedes`?
`P[i] is a` is (PNI) a very risky thing to write. Those are one-letter strings, which are most pro
More
This is a nice example of how chaining can help you write better code.
First, x == 1 and y == 1 can be written as x == y == 1.
Then you see you have it also in equivalence.
if x == y == 1 or x == y == 0:
Then you see you can factor out x == y.
if x == y in (0, 1):
Then you realize that
More
It's nice and all, but haven't you overengineered it a bit? :-) The board has 64 squares, not a million. :-)
More
Few nitpicks:
* romanNumeralMap really should be a dict. Yes, I know it won't be sorted, but you can sort it by value without problems, and it would probably help readability.
* input checking leaves a lot to be desired. What if n is "123a"? isinstance(n, int) (or using ABC) would be much better.
More
Instead of re.match with `.*`, use re.search. It's there for exactly that purpose. ;-)
For the pattern, you can use `("[A-Za-z]+ "*3).strip()`, or `" ".join(["[A-Za-z]+"]*3)`. Of course, if you name that pattern `word`, it would be much easier to follow.
More
You don't need those \\ continuations (you're inside parentheses).
Also, line 10 is just "if r > res - 1e-5:". Even that 1e-5 is probably overkill... you know any particular case where float arithmetic let you down in this task? I didn't care about that, and my solution works fine.
Line 3: wasn't
More
> Output: The list of integers.
Yeah, right. :-P
BTW, I'm quite sure I tried a generator anyway (a long time ago), and it didn't work. Did you change something?
More
Not really puzzling if you know that str times negative is "", but still cool. :-)
More
If you don't want to be boring, you can always look at the @StefanPochmann's solution. ;-)
More
Don't separate : by a space on the left ("else :"). It might look cute, but almost nobody else does that. Try to be more consistent with those spaces all in all (line 6).
== can be chained: number % 3 == number % 5 == 0
You don't need result: you can just return whatever you want when you want, yo
More
Could be simpler, cleaner, _and_ use less memory if you removed the brackets.
''.join(letter for letter in text if letter.isupper())
BTW .istitle is not exactly the same. It is used when the desired output has only first letter of word emphasized by case. Although the test example gives exactl
More
LOL. Nice "inside the box" technique. But I can't make it work. Did CheckiO randomize some tests? Does it still work for you?
More
For a beginner, it's pretty smart. ;-) But...
blah if cond else 0 ~~~> blah * cond
That's exactly what multiplication with bool does.
More importantly, `words = words.split()` has no advantages (over just `for word in words.split()`) and many disadvantages.
First, by rebinding the name
More
Don't ever index by index. Pythonic idiom for this is accessing a dict by key.
(a, b, c)[(d, e, f).index(x)] ~~> {d:a, e:b, f:c}[x]
Much faster (logarithmic instead of linear), shorter and more readable (keys and appropriate values are together).
More
''.join and generator expressions would be much nicer solution instead of that C-like loop.
(Not directly applicable since numbers are small, but might be interesting: [Schlemiel the painter story](http://www.joelonsoftware.com/articles/fog0000000319.html))
More