57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 23 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.
Ok, first: Too. Many. Comments. Really.
This is not C, where you write the code primarily for the processor, so you have to explain to the human readers as an afterthought. Here you write pseudocode, that is incidentally executable. Having so many comments indicates you're misunderstanding someth
More
Nice. BTW, there are set literals in Python: set([first, second]) -> {first, second}.
More
Cool. :-) You can use .count('1', 2) to be explicit you're starting to count from position 2 (here it doesn't matter, but it could if someone decides to count zeros instead).
More
.replace('0', '1') is really a hack. :-) If you want to be clear, if (or filter) would be better.
Also, total is a strange name for a product. ;-)
More
Namespace dicts are usually initialized via kwargs.
dict(e=1, a=1, i=1, ...)
[Of course, you might argue whether VALUES _is_ a namespace dict, but I think the readability gain is positive anyway.:]
---
Otherwise, as opposed to many solutions that are claimed to be clear and Pythonic, this on
More
* jackdied: Does your class have two methods, one of which is `__init__`?
* veky: errrm... no? :-)
([context](https://youtu.be/o9pEzgHorH0?t=180))
More
The algorithm is beautiful, of course - but others told you that. Code, not so much. You use various antipatterns here (`.find` instead of `in`, over-and-over-again producing of new strings with `.replace`, nested `if`s, treating digits specially, hardcoding a lot more than needed...) and those spac
More
re is obviously an overkill here. With the necessary escaping it is even longer than ordinary index (or my approach:). And you don't even use IGNORECASE.
Nice use of bisect.insort. :-)
That ugly offset calculating can be completely removed, if only you replace "enumerate" with "reversed" in li
More
1. That converting to binary (BTW did you know about bin function?) has way too many parentheses for my taste. :-) 1<< has too low priority, 2** has big enough (and optimizer is smart enough). Outer () around bool are superfluous, probably a remnant of C casting thinking:-D. And cast to bool is not
More
Much clearer: define min_max with its true signature (reverse:bool, *args, key=None) and say
min = functools.partial(min_max, False)
max = functools.partial(min_max, True)
More
Nice UF. But of course you don't need a class.
Line 44: You don't need `list()`. In fact you don't need `set()` either. ;-]
Line 45: `sorted(eggs, key=spam)[-1]` is also known as `max(eggs, key=spam)`. Timsort _is_ damn fast, but max is linear. :-)
Line 19: see `dict.fromkeys`. Very useful and fe
More
Nice and straightforward. But Dijkstra is massive overkill. The point is, there are only two paths (+ degenerate case) you have to explore. See my solution, I can write it in long form if you need.
More
Do you _really_ write this on your mobile phone? And does it have Python installed? :-)
More
1. sequences are boolable. "if not l" is more pythonic than "if len(l) == 0".
2. candidates can be written as a big list comprehension (again, it doesn't have to be in one line, in fact it can have the same structure as your original lines 6, 7 and 8).
3. range(0,10) is just range(10). Think o
More
frozenset is much simpler than tuple of sorted, since there are no repetitions.
itertools.chain is an overkill (fortunately you didn't use itertools.chain.from_iterable, a powerful function with a horrible name:). set().union is all you need. ;-)
BTW the "chopsticks" in the last two lines are real
More
As you see from the comments, methodcaller is good from educational point of view. :-) But there is a much easier way: just use unbound method.
map(str.split, calls)
More
@oduvan: Much improvement. I usually solve your missions with just one import from stdlib, now I had to use three. :-D
More
Cool. Not really general, but here is a nice hack someone might find amusing: you can replace max(0, x - 1) with x - bool(x). ;-)
More