40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi, this isn't very Pythonic :( I'm wondering how it got 57 upvotes.
```python
from math import acos, degrees
def is_correct_triangle(a,b,c):
return a+b>c and a+c>b and c+b>a
def angle(a,b,c):
d = (a**2 + b**2 - c**2)/(2*a*b)
return round(degrees(acos(d)))
def checkio
More
Hi, this is doable without `if` as `and` is Python is short-circuiting: `return len(args) and max(args) - min(args)`. Regards, suic
More
Hi, `sorted()` doesn't modify the `number_array` variable => you can omit `x`.
More
Hi,
1. you can save an `int()` conversion
2. you canremove the `liczba` variable
3. other way of solving this mission is using `filter()` and `reduce()`
I'm not saying that either of the below solution is better than yours :) My point is that this type of refactoring is useful for exploring Pytho
More
Hi, nice math-based solution. :)
few Python tweaks:
1. `divmod()` is an excellent built-in function.
2. __`str`__ has `str.count()` method, which can do the work for you: `bin(number).count('1')` as `bin()` returns a __`str`__.
Regards,
suic
```python
# divmod
def checkio(number):
wynik = 0
More
Hi,
I this case you let Python to do the work fork you:
```python
ostatni = array[-1]
suma = sum(lista)`
# or even
suma = sum(array[::2])
```
You don't need the `else` branch.
Regards,
suic
P. S.: Jest to jakas praca domowa?
More
Hi, `bin()` returns a __`str`__ so `str()` is redundant.
More
Hi, let's have a look at your `get_bin` function:
```python
def get_bin(number):
return (list(map(int, list(str(bin(number))[2:]))))
```
1. `bin()` returns a __`str`__ => __`str`__ is redundant.
2. __`str`__ is iterable => `list` is redundant.
```python
def get_bin(number):
return list(map
More
Hi,
1. Instead of lines 10-14 you can write: `return sum(x[0]!=x[1] for x in zip(*(map(int, i) for i in (x, y))))`.
2. Look at `^` (alias `xor`) operator.
Regards,
Gabriel
More
Hi,
#### In Python you usually iterate over elements
```python
def find_message(text):
msg = ""
for char in text:
if 65 <= ord(char) <= 90:
msg += char # shorthand
return msg
```
#### How to check if string is uppercase
```python
65 <= ord(char) <= 90
'A' <= char <
More
Hi,
1. Line 2 is redundant: __tuple__ is iterable.
2. Line 3 and 4 are redundant: `return ','.join(x).replace('right', 'left')`
Regards,
suic
More
This solution is for demonstration purposes ([see](https://py.checkio.org/forum/post/10113/help-please/)).
More
Hi,
1. `[]` are redundant :) `sorted` takes any iterable including generator expressions.
2. If you assign `f = first.split(',')` and `s = second.split(',')`, you perform the splitting only once per each word.
Regards,
suic
More
Hi,
instead of the condition on line 6 you could write:
sum(i.isdigit() for i in data)
# or even better
any(i.isdigit() for i in data)
Other option is to combine _sum()_ and _filter()_
sum(filter(str.isdigit, data))
More
Hi,
nice solution, but why don't you returned the condition?
return len(data) >= 10 and contains_digits(data) and contains_upper(data) and contains_lower(data)
\-----------------------------------------------------------------------------------------/
More
Hi,
I'm sorry, but this is quite un-pythonic. I'm wondering how this could get 13 votes.
Let me explain:
1. Lines 18-21. This is an anti-pattern. Your condition is a __bool__ which you can directly return: `return num and lower and upper`
2. This isn't pythonic: `for i in range(len(data)):`. Norma
More
Hi,
there's is quite a lot of redundancy in this solution:
return len(data)>=10 and all(re.search(pat, data) for pat in ('[0-9]+' ,'[A-Z]+', '[a-z]+')):
and also an anti-pattern:
if cond:
return True
else:
return False
# is the same as
return bool(cond)
More
Hi, nice one. You can shorten it a bit (see [this](https://checkio.org/mission/median/publications/suic/python-3/variation-on-paolobrasolins-theme/)). :)
More