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.
That empty line 5 is not really needed, or at least it should be less than empty space in line 14 (which would have to be 2 empty lines in that case:), and of course the context of lines 1, 2 and 15 is also not needed. But line 5 could be filled with a docstring. ;-)
Also, Python's `not` operator i
More
Again, when you remove that superfluous `print`s, you see that rebinding in line 4 is unnecessary. Just
for word in words:
počet is now ok as int, since you really have to count. Shortcircuiting (lines 8 and 9) is also ok. But after that...
first, don't compare things as `== False`. If you re
More
Again, horribly complicated. And why do you put the median under data[0]? Don't you have a nicer name for it? E.g., 'median'. ;-]
More
This is a great example of OOP vs ADT dichotomy (see http://www.cs.utexas.edu/users/wcook/papers/OOPvsADT/CookOOPvsADT90.pdf). If you put everything in an object, it looks like above. But if you use smart data types, you see that reached and infected are just sets, index is id of node, security_leve
More
Was it really easier to build that str for eval, than to build the product itself? *= is as complicated as +=. :-)
More
Try to figure out how this works. Would a similar algorithm work for board size different than 8x8? ;-)
More
First, those results can be simplified. Since bools _are_ ints, equivalence can be just x == y. And implication can be x <= y. ;-)
Also, once you open { (or other parens), you can have newlines in the code for free until you close it. Much nicer than horizontal scrolling:-).
And, dicts with identi
More
Nice, but wasn't adding +"!" simpler than replacing "n"?
Also, drop the [] inside join().
More
Line 18 is ugly. Three suggestions:
* (simplest) Use dictcomp: {a:[] for a in range(1,9)}
* (correct but long) Use graph.setdefault(node1, []).append(node2)
* (most correct) Use collections.defaultdict(list) (BTW maybe set would be nicer)
* (hacky) Use a list: indices are small positive ints anyway
More
You can use if...else expression. return -1 if len(array) <= n else array[n]**n.
Also, (binary) pow can be written as an operator **.
Otherwise, fine.
More
Lines 13~15 are _horrible_. Really. I still don't think you really understand what's going on there and why it "works". (What is hasUC for "aBcDe"?)
And now for minor details:
bool is unnecessary, task says anything boolable will be accepted.
What does data.isalnum() do here? It's a precondition,
More
Again, use key argument instead of decorating and undecorating. Using _min_ to solve _most_ wanted letter is really confusing. And drop the [].
max(string.ascii_lowercase, key=text.lower.count)
Nicer, right? :-)
More
You see how complicated code becomes when you artificially try to single-exit your functions? This is not Pascal. Just return it when you get it.
for combo in b:
if combo == "XXX":
return "X"
if combo == "OOO":
return "O"
return "D"
Even better, why
More
Don't give irrelevant names to things used only once. w = word.lower() doesn't accomplish anything.
And a.find(b) != -1 is a _really_ strange way of writing "b in a".
Also, you can use sum for counting. But that's wizardry. :-)
More
Use unpacking in for:
for dx, dy in neighbors:
Also, use chaining:
0 <= x < len(...)
"if blah and something == 1: count += 1" can be "if blah: count += something", right? something can be only 1 and 0 here.
More
Nice. When someone asks me what my solution does, I'll just refer them to you. :-D
More
Cool! Why this isn't in Creative category? :-)
BTW dna really should be a bytes (b'...'). Then you wouldn't need all these encode/decode shenanigans. ;-)
More