57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 20 hours ago
Member for 11 years, 6 months, 6 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.
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
First,
array[len(array)-1] ~~~> array[-1]
Second, don't ever write empty except! Say what you really guard against:
except IndexError:
More
Since they say that imitation is the sincerest form of flattery, thanks. :-D
(4 instead of 5 for that ugly loop management inside, and other repetitions, such as in the last line. Yes, they save lines, but hurt aesthetics.:)
More
Not boring at all. That [Chekhov's product](https://en.wikipedia.org/wiki/Chekhov's_gun) in first line is very interesting. I deeply wonder what was its intended purpose in the never-revealed third line. :-DD
More
Exercise: find all the places in the code where pairs (tuples of len 2) have been used. ;-)
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