57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 1 day 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.
Yeah, at first I thought inheriting from Counter would be a nice idea. However, it's insistance on reducing negative counts to 0 is painful to fight against.
Instead of that ugly polynomialize, you could have written something much more elegant: eval accepts a locals() dict as a second argument. So
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
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
Nice. Of course, can be expressed with any.
any(word.endswith(suffix) for suffix in words_set for word in words_set - {suffix})
Or itertools.permutations, if you're in the mood. :-)
More
Line 4 doesn't serve any purpose, you know? :-) In fact, you can just return the expressions from lines 6 and 8 directly. But it's nice to name at least the return value, when the function name is totally uninformative. ;-)
"!= 0" can be removed from line 5. Read it as "if there is a remainder".
I
More
I think set(blah) & set(nyeh) is still nicer than set(blah).intersection(nyeh). But not much.
More
Don't write empty except. It almost never means what you think it means.
For example, imagine someone confuses order of arguments, and calls index_power(3, [1,2,3,4]). You'd want TypeError, right? But you get -1. :-(
More
Since you have two lines anyway, how about extracting definition of l to separate line? :-)
Also, you shouldn't use mutable defaults unless you _really_ know what you're doing. ps=() is much better. (Usually, = in default definitions doesn't have spaces around it. At least PEP8 says so.:)
More
inside is just `max(divmod(top-1, 4)) < 4 - length`. And set([spam for egggs]) is `{spam for eggs}`.
And if you return a set(sides) from square, you can just use subset operator (`square <= lines`) in the last line.
More
:-) Even if you _did_ want to convert words to a list (though there is no reason for that here), there is a nicer and explicit way:
for y in list(words):
More
Pytonic way of writing switch is not enormous ifchain, but a dict. Great advantage is that names and codes are next to each other, so you can see what's what.
def boolean(x, y, operation):
code = dict(
conjunction = x and y,
disjunction = x or y,
impl
More
If you really want a faster algorithm, use collections.deque instead of list. Line 8 is O(n), and deque.popleft is O(1).
More
Instead of lambda with \*, you can use `operator.mul`. Or if you don't want to import one module more, you can use `int.__mul__`.
int(z) is duplicated, since this is the reverse of usual listcomp paradigm: you need map first, then filter over that. So you can use the building blocks directly.
More