57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 2 hours 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.
I think set(blah) & set(nyeh) is still nicer than set(blah).intersection(nyeh). But not much.
More
LOL about that "-1" in line 8... isn't it more clear to use slicing?
f0, f1 = map(bin(first)[2:].count, "01")
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
:-) 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
It's fascinating that the same solution, somebody puts under puzzle, somebody under clear. :-P
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
Now, this is a real puzzle. :-D Did you first write/find the joke and then realized it can be used here, or did you search for / wanted to construct a relatively short joke that had "checkio?sum" as a casefolded subsequence, and found this one?
(Of course, my [Magnum Opus](https://py.checkio.org/mi
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
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
Well, that's obvious. :-) Although, line 5 could be
result.extend(flat_list(item)), to better parallel the result.append(item).
More
You can rename while importing:
from statistics import median as checkio
;-)
More
Good. Now, let's try to invert our logic a little. We have two "moments of truth": in one case, we call extend and we do call flat_list on the item, while in another, we call append and we do not call flat_list on the item. Every other combination is either an error, or nonsense. Can we have _one_ m
More
Yup, Python has finally got its unquote operator. :-D
Of course, you can also do it [without eval](https://py.checkio.org/mission/boolean-algebra/publications/veky/python-3/an-operator-by-any-other-name/?ordering=most_voted&filtering=all). :-)
More
Nice and transparent, if a bit boring, especially those at the beginning. A few details:
* if z in Special.keys(): you don't need .keys . dict knows how to check containment itself.
* ''.join accepts a generator. ''.join(...) is more readable, memory efficient, fast and overall pythonic (not t
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