40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, this is inefficient because __str__ is immutable i. e. each `result += char` creates a new string. You could use:
1. [_filter()_](https://docs.python.org/3/library/functions.html?highlight=filter#filter) or [_generator expression_](https://docs.python.org/3/whatsnew/2.4.html?highlight=generator
More
Hi,
1. _list()_ is redundant. [_filter()_](https://docs.python.org/3/library/functions.html?highlight=filter#filter) returns an _iterable_ which [_str.join()_](https://docs.python.org/3/library/stdtypes.html?highlight=join#str.join) can consume.
2. __str__ has [_str.isupper()_](https://docs.python
More
Hi, all the `if`s are redundant:
~~~~
# as:
if cond:
return True
else:
return False
# is the same as:
bool(cond) # when the condition is itself a bool than bool() is redundant
# and:
if cond_a:
if cond_b:
...
# is the same as:
if cond_a and cond_b:
...
# ------------
More
Hi, you could write:
1. `return not len(alphabet) > 0` instead of lines 7-10
2. `alphabet = list(string.ascii_lowercase)`
3. `text = text.lower()`
More
Hi, what about [__deque__](https://docs.python.org/3.5/library/collections.html#collections.deque)?
More
Hi, you could you `ge` and `le` from the `operator` module.
from operator import ge, le
def max(*args, key=lambda x: x, cmp=ge):
...
def min(*args, key=lambda x: x, cmp=le):
...
More
Hi, I've made a few changes:
def checkio(first, second):
longer = max((first, second), key=len)
shorter = min((first, second), key=len)
common = (word
for word, word2
in zip(shorter.split(","),
longer.split(",
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 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 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, `sorted()` doesn't modify the `number_array` variable => you can omit `x`.
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, 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, `pass` in `if..else` usually indicates redundant branch like in this case:
```python
def checkio(number):
result = 1
for ch in str(number):
i = int(ch)
if i != 0:
result *= i
return result
```
More
Hi,
Using `list` as a queue isn't optimal. `collections.deque` would be a better option here as `p = q.pop(0)` is `O(n)` while `q.popleft()` is `O(1)`. (see a nice summary [here](https://wiki.python.org/moin/TimeComplexity))
Regards,
suic
More
Hi, `lambda` is redundant:
```python
return filter(str.isupper, text)
```
Regards,
suic
More
Hi, `list` and `lambda` are redundant:
```python
return ''.join(filter(str.isupper, text))
# 1. filter expects a function as its first argument and str.isupper is a function.
# 2. `str.join` accepts any iterable including filter object.
```
Regards,
suic
More
Hi, this solution isn't quite Pythonic.
Regards,
suic
```python
import re#(dundant)
def find_message(text):
for ch in filter(str.isupper, text):
message = message + ch # inefficient as str is immutable
# (on the other hand doesn't matter for small inpu
More