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.
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
Why line 6? Tuple has all the interface you need.
Nice algo, of course it can be expressed with sum.
sum(val1 < val2 for end, val1 ... for val2 ...)
More
Eta-reduction applies here: checkio = \_\_builtins\_\_['s''um']. And as you see, + is not needed. ;-)
More
Inspired by Zlomovsky's [Lambda-91](http://www.checkio.org/mission/count-neighbours/publications/zlomovsky/python-3/lambda-91/#comment-26172) (also known as "WET is shorter than DRY":) solution. They just didn't take it to the extreme. :-D
More
BASE.find(str_number[i]) really could be factored out.
Instead of that ugly index manipulations, you can use enumerate (and possibly reversed).
More
Lines 4,5,6:
digits = lowers = uppers = 0
Line 1: unnecessary. :-)
Lines 8~13:
digits += c.isdigit()
lowers += c.islower()
uppers += c.isupper()
or if you insist on using unbound method, remove initialization and just say
digits = sum(map(str.isdigit, data))
Lines 15~18:
More
Nice idea, but really too complicated implementation. See:
checkio=lambda t:3*"True"in"".join(str(w.isalpha())for w in t.split())
More
Line 1 expression can just be "secs // 60 + (secs % 60 > 0)". bool _is_ int. ;-)
That antipattern in lines 10~13 really should have been using collections.Counter. Learn about it, you'll love it. ;-)
Lines 16~19 are _precisely_ the reason why Guido finally added conditional expressions to Pyth
More
An interesting approach. However,
a minor point: you can initialize them all at once (see below)
and a bit bigger point: flat is better than nested. Indentation is cool, but is not really optimized for such nesting. This is probably better:
if len(data) < 10:
return False
upper =
More