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.
I think I don't need to tell you how repetitive this code is. And still it doesn't really work. You can have a false callable as key.
And why `**kwargs` instead of just telling what you need?
def min(*args, key=None):
Or even, since performance obviously isn't a concern when you're reimplemen
More
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
Of course, you can just
return [x for x in ...]
But in this CiO context, giving a return value a semantic name is even justified. Though of course, not in the real code - then the _function name_ should be used for that purpose.
More
Too many indices! :-o But this is minor.
Real problem is using 10 and 100 as magic numbers. Besides being
maintainability hell (network expands, and in some random moment in the
future, your code gives wrong results silently), documentation is lacking.
Comments do help at the moment of assignm
More
Nice shortcircuiting when len < 10.
Lines range(9, 18, 3) ;-): comparisons can be chained.
if 'a' <= i <= 'z':
Even better: `if i.isupper():` (also `islower` and `isdigit` are available).
Comments and those print "debug" statements should be deleted before publishing.
It's nice that you _co
More
Horribly complicated. Did you see the hint? .count is your friend.
del data[data.index(i)] ~~~> data.remove(i)
Partial unrolling of loops (line 6 == line 17) is a very common source of very hard to find bugs. Don't do that. Instead of lines 6 and 17 just write it in line 10.
Here
More
Line 6: chaining is cool.
if number % 3 == number % 5 == 0:
Lines 8 and 10: `not` is cool too when checking divisibility.
if not number % 3:
And `str("Fizz")` is like `list([3, 5])` or `float(3.14)`: completely redundant. ;-]
More
You don't have to write len(array) inside array[...]. Just
... * array[-1]
About součet: it's called `sum` in English.
def evens(array):
for index, element in enumerate(array):
if not index % 2: # remember this from FizzBuzz? ;-)
yield element
souč
More
As I said, line 2 is just
if not args:
Or you can hackingly use the fact that 0 is the same:
return len(args) and (...big - ...small)
(BTW naming can also be chained: `big = small = args[0]`.)
But for that to function, you have to calculate big and small in expressions. However, that's
More
elif can be handy. :-) And instead of keeping it all in a str, it's better to keep it in a list, `' '.join`ing it at the end.
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
You are not modifying a builtin method here. ;-D
More
Nice and explicit, but you might want to learn about "set" type, and & operator on them.
More
You do realize that you don't need max_count at all? As soon as count reaches 3, you can return True.
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
You're repeating len(data) // 2 too much.
half, odd = divmod(len(data), 2)
if odd:
... data[half]
else:
... (data[half] + data[half-1]) / 2
Also, `...` should be direct returns. This is not Pascal, you don't have to single-exit your functions. As soon as you find the re
More