40
Last seen 1 day ago
Member for 9 years, 11 months, 3 days
Difficulty Advanced
You can remove this:
if number>0 and number <= 1000:
else:
None
The is enough as all the tests meet this condition.
More
It's a matter of taste but: This is more __noisy__ than clear, especially these boxes from # and the print statement are really not necessary.
This
# return sum(array[0::2])* array[-1]
is quick and clear.
It would be clear enough to add a long comment explaining what [0::2] and array[
More
1. See my comment about ifs to your solution of House Password
2. Shorthand:
a = a + 1
the same as
a += 1
Try to look at [assignment operators](http://www.tutorialspoint.com/python/python_basic_operators.htm). :)
More
Two small things:
1. You can directly rename the argument i. e.
def checkio(password):...
2. The if clause is not necessary. You can replace:
if :
return True
else:
return False
with:
return
More
The return None in your code is never reached, you may remove it.
More
Few tips:
array[len(array) - 1] == array[-1] # there's no need to write len(array)
n = n + 1 --> n += 1
0 % 2 == 0 # you can omit n == 0 in your if clause
The code in else branch doesn't have to be in else branch.
More
_nbin_ and _mbin_ are both _str_ which is iterable there for using list() in lines 10 and 11 is superfluous. And also you can write:
size = max(len(nbin), len(mbin))
More
You can use the [str.rjust](https://docs.python.org/3/library/stdtypes.html?highlight=str.rjust#str.rjust) method for this:
fill = abs(len(n) - len(m))*'0'
if len(n) < len(m):
n = fill + n
else:
m = fill + m
More
You don't have to use third variable two swap values of two variables. You can simply write:
if n < m:
m, n = n, m
instead of:
if n < m:
tmp = n
n = m
m = tmp
More
Good job! There's no redundancy. And it's even safer than it has to be, as all inputs in the tests are already sorted :)
More
A few comments:
1. In fact lines 5-7 are superfluous as a, b and c don't have to be sorted.
2. Then:
a, b, c = length
is the same as
a = length[0]
b = length[1]
c = length[2]
3. Consider creating a separate function from:
round(degrees(acos((b * b + c * c - a * a)
More
This code is a good candidate for refactoring. Look at the _cos = ..._ and _angles ..._ lines (5 - 10). There's exactly the same pattern 3 times. Consider to create a separate function at least for _cos = ..._ lines.
More
You can avoid the duplication on lines 15 and 16. E. g.:
a_1, a_2 = (round(math.degrees(math.asin(height/lengths[i]))) for i in (0, 1))
More
Small thing: This is a good example where you can use lambda instead of nested def.
More
You could write:
return first_letters == second_letters
instead of:
if first_letters == second_letters:
return True
else:
return False
More
One small thing:
if x==y:
return True
return False
is the same as:
return x == y
More
This is a bit "noisy": One of the _for_ s is superfluous. With (e. g. list) comprehension and using all() you can reduce the remaining _for_ and _return_ to one line.
More