57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 23 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.
Missing/nonmissing spaces make this code ugly at a first sight. "curage" is probably misnamed, should be "current_opacity", right?
Also, your fib generator is too complicated. Use tuple assignment for great good. :-)
def fibgen():
a, b = 0, 1
while b < 5e3:
a, b = b
More
Your code has a weird mix of using //2, /2 and /2.0. (That's probably the consequence of using Py2.:) Either stay with Py2 (without `from __future__ import division`), use `/2` and `/2.0`, or (much better;) switch to Py3, where you use `//2` and `/2`.
Also, length should be properly spelled. Or jus
More
First,
from string import ascii_lowercase as alphabet
letter_stat = dict.fromkeys(alphabet, 0)
Then,
if 'a' <= ch <= 'z':
is completely ok. Or (simpler and more to the point of what you really want to check)
if ch in letter_stat:
And last, Python has a powerful battery named ma
More
A fun fact: checkio can be written as
(None, units, tens, hunds)[len(str(number))](number)
;-)
And a divmod here and there should definitely help.
What you did with `s_hp` (naming a partial result) can also be used with `OTHER_TENS[dt-2]`.
You can also strip spaces later with .strip(), so y
More
set(map(lambda x: blah, filter(lambda x: cond, spam)))
should _really_ be written as
{blah for x in spam if cond}
It's almost twice shorter, clearer and less noisy. Comprehensions are cool. ;-)
And learn to use collections.deque as a queue. ;-)
More
You could at least remove line 18, if you intended to disregard its hint so completely. :-P
More
Factor:
for limits in 'az','AZ','09':
if not re.search('-'.join(limits).join('[]'), data):
return False
return len(data) >= 10
More
"word for word" literally means unnecessary repetition, right? :-D
",".join(sorted(set(...).intersection(...)))
Also, here & would probably be nicer, since things are symmetric. And `set(arg.split(","))` would probably look nicer factored out into a separate function.
If you want to eliminate
More
Here `str` is completely unnecessary (.split gives a `list` of `str`s). For the rest, see comment to other solution. ;-)
More
Of course. But the interesting thing is that you don't have to make a new function at all - since you're just specializing a builtin.
checkio = functools.partial(sorted, key=abs)
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
You're overusing `continue`.
if 0 <= i < len(grid) and 0 <= j < len(grid[i]) and (i, j) != (row, col):
count += grid[i][j]
(Or better yet, `yield grid[i][j]` and `sum` it from outside.;)
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
Yes, that is a nice idea. But the implementation can be much nicer. :-)
More
Little Fermat is cool, but I'm more surprised by the fact that 0-something isn't always the same as -something. :-O
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
What do you think lines 4, 5 and 6 do? :-)
Also, at the end, `' : '.join`.
More