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.
data.sort()
could be better than sortedData... but it depends on what exactly the caller is expecting, and the task isn't really clear on this.
That -1 offset in line 4 is ugly, and you can do without it (just look to the left in case of even length). And since you use both //2 and %2, divmod
More
LOL... that's a very roundabout way of doing it. :-) Whitelisting is much simpler than blacklisting.
collections.Counter(filter(str.isalpha, text.lower()))
And why sort before, instead of after?
And more puzzlingly, why count from start for each _instance_ of each letter??
More
You can assign multiple targets:
uppercase_letters = lowercase_letters = digits = 0
You can add bools directly:
digits += letter.isdigit()
Or even count directly without writing loops:
digits = sum(map(str.isdigit, data))
(But of course, considering the task, it's better to use `an
More
Nice idea, but few things are ugly.
First, that `400` limit is really jarring. There is no reason not to implement proper floodfill. It's really not much harder than what you wrote.
Line 9: If you made dirs a set (just put {} around), you could write
explore |= dirs & area - set(flow)
Line 2
More
Sorry, but _you_'re the cheater here. Read the task carefully.
And the 10**4 is just bad. :-P
More
First, many things know how to bool:
if not array: return 0
(or even better, if array: do your computation // else: return 0)
And then you don't need else. Whatever part returns what it computed, other will not execute.
Second,
for a in [b for blah if cond]:
stuff(a)
is much cl
More
Huh. You've employed some very powerful techniques for making your code longer than necessary. :-P
First, not every condition must have a relation operator. Specifically, bools remain bools after comparison. And they remain themselves after comparison to True. So if cond isinstance of bool, then al
More
You can use *=.
And I always find it funny when someone uses continue when the "rest of the loop suite" is just one statement. Wouldn't it be easier to reverse the logic and guard the statement itself?
for x in str(number):
if x != "0":
prod *= int(x)
[BTW maybe the condit
More
I'm not quite sure what magic skills you're referring to, but you might be amused by another one:
sum(array[::2]) * array[-1] if array else 0
More
Again, args can bool without taking their len and comparing it to 0. "if args:". Or just
max(args)-min(args) if args else 0
More
You don't need parens in line 6. and binds less tightly than ==.
Even better, all are equal. You don't need and at all.
if number % 5 == number % 3 == 0:
if...else expression can also be used here, but it's probably overkill in this task.
More
"if" is unneeded. Nothing horrible will happen if you replace something that isn't there.
More
Hm. Do you _really_ think of this task as classifying result _first_ by x and y, and _then_ by operation? People usually read that truth table by columns, not by rows, though your interpretation is of course possible. :-)
(Maybe I shouldn't be so surprised, since I wrote a solution that reads it by
More
Nice. Of course, that threefold repetition of "x" invites one to write it pointlessly, but this is also perfectly fine.
More
You can use +=. But better is to use "".join. Just like sum when initial value is 0, use "".join when initial value is "".
And there is really no need for nested loops. Just
for y in text:
More