57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 14 hours ago
Member for 11 years, 6 months, 24 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.
First, do you really need randomization? You shouldn't, this is a deterministic task. At least you should seed the generator to something fixed.
Second, you really like these set methods, hm? Sometimes conversion is much better:
not a.symmetric_difference(b) ~~~> a == set(b)
Again, indi
More
LOL @ `'.' not in i[0]`... you obviously meant `'.' not in i`, or `'.' != i[0]`.
But much clearer would be just `if i in {'X'*3, 'O'*3}:`
Nice factoring out of `board[1][1].isalpha()`. :-)
More
A classic example of overthinking things. You can just remove line 1, and OrderedDict(), and .items(), and everything will work. :-D
More
roundoff = lambda x: '{:.{}f}'.format(x, decimals) if decimals else str(int(x))
return roundoff(number / base**i) + p + suffix
Same length, clearer IMO.
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
First, precondition says that all elements of numbers_array are ints. So `int(` in line 4 is unnecessary.
Second, you then have for your key
lambda x: abs(x)
What's that function? Takes x and gives abs(x). I know a much simpler function that does exactly the same. Of course,
key=abs
Als
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
Nice. However:
len([y for y in blah if cond]) ~~~> any(cond for y in blah)
is much clearer and it shortcircuits, while len-version doesn't. But even better IMO would be if connected were a _function_ taking an index and returning a set. (It could be local to `capture`, so it could access
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
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