40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
You can write:
nbSecure += angelLeft in pawns or angelRight in pawns
instead of:
if angelLeft in pawns or angelRight in pawns:
nbSecure += 1
More
I like this solution.
A few comments/pieces of advice how to make it shorter:
1. print( r ) at the end is superfluous as it's never reached as there is a return statement before it.
2. you don't need to put r in brackets in the return statement _return r_ is the same in this case.
3. you can use r
More
You could write:
return first_letters == second_letters
instead of:
if first_letters == second_letters:
return True
else:
return False
More
Small thing: This is a good example where you can use lambda instead of nested def.
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
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
Hi, as __str__ is immutable is not a good type for accumulating values. Look at _filter()_.
More
Hi, lines 2-5 are useless and you don't need `my_string` and `my_new_string`:
return "".join(phrases).replace("right", "left")
More
Hi,
1. Last if is redundant. `return count == 26` is enough.
2. __str__ is iterable so `list(string.ascii_lowercase)` is redundant.
3. You don't need to check all lowercase letter. If any of them is not in `text` result is False.
for i in string.ascii_lowercase:
if i not in text:
More
Hi, it's a bit repetitive. I played with it. Result is [here](http://www.checkio.org/mission/roman-numerals/publications/suic/python-3/arandomusernames-refactored/).
More
Hi,
1. For the left side you could use _filter()_:
set(filter(str.isalpha, text.lower()))
2. For the right side you could use _set()_, _map()_, _range()_ and _chr()_:
set(map(chr, range(97, 123)))
3. In fact you don't need the right-hand side:
return len(set(filter(str.isa
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
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
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
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
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
_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
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