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 writing a tribute to me, at least drop brackets inside parentheses.
sum(x for i, x in enumerate(array) if not i%2)
But in fact, slicing is much simpler. You can use itertools.islice if you worry about memory.
More
Why dict instead of just a list? Also, those lambdas don't need to have the same arg specification, you can name them better than a[...].
More
OMG. The dreaded "else: pass" pattern. :-D
Also, why do you check for tuple at some point? (and for list at another!?) The code shouldn't depend on exact types passed into min/max.
More
You invented a new pattern: iterecursion. :-P
And you were very close. You just needed to drop the lower half of your code. :-D
for value, notation in roman.items():
repeat, num = divmod(num, value)
yield notation * repeat
More
Wasn't it easier to do that `set(connection.split("-"))` thing only once? :-)
Also, `break else return` is a powerful pattern that's better than bool flags.
See [my solution](https://py.checkio.org/mission/find-friends/publications/veky/python-3/tinus-trotyls-pythonified/) for implementation. :-)
More
Yeah, something like that. Just a few Pythonic nitpicks:
dim and width can be (kw-only if you're paranoid:) parameters to checkio.
def checkio(edges, *, dim=2, width=4):
[Even better would be to _infer_ them from `edges`, and that is what I really meant as a challenge, but I see it wouldn't
More
What's this epidemic separation of return with two empty lines from the rest of the function?? Where do you get this idea, people? :-/
More
It's funny how your naming quickly deteriorated from
most_wanted_letter_alpha # wow, I'm feeling so powerful
to
a # ah, to hell with it already!
:-D
More
Interesting idea to use numpy to solve the system. However the system is
modular, so you have to guess k (additional number of turns) so the whole
thing becomes a bit clumsy. (But still, explicit loop would probably be
better than recursion with a default parameter.) Numpy _can_ be exploited
to
More
Too bad attempts aren't reversed (divisor,remainder) - then {d for d,m in a} could be set(dict(a)). ;-)
More
Up to the input, which is immutable (tuple of str), this has a **constant space** complexity - that is, it writes to a fixed number of memory cells, no matter how long the input is. It shows directly how beautifully iterators fit together. I don't think any other solution satisfies that criteria.
A
More
26 is not so magical. I expected 2847 or something like that. ;-D
More
Seems ok. But you don't have to make tmp (as a name) and lstext (at all). Try this :-)
import re
p = re.compile(r"\W+").split
def checkio(t, l=len, V = "AEIOUY", z=zip, S=sum, m=map):
def s(w):
if w.isalpha() and l(w) > 1:
for c, d in z(w, w[1:]):
More
For all those who wondered how my "golf course" looks like in the zeroth iteration. I intentionally didn't "compress" any of this code, this is what I wrote directly. Compressing the above is left as an excercise to the reader. :-D
More
Lines 2, 3 and 4 can be written at once:
tlist = list(filter(str.isalpha, text.lower()))
or if you don't like unbound methods,
tlist = [x for x in text.lower() if x.isalpha()]
Line 5: please avoid semicolon if in any way possible. "show, counter = 0, []". BTW why "counter" name f
More