40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
1. All `== True` checks are redundant.
2. All `else` branches are redundant.
3. Finally: When you use _any()_ with `and` or _all()_ all the `if`s are redundant.
Your code after step 2.:
def checkio(data):
if len(data) >= 10 :
if any(c.islower() for c in data):
if
More
What about:
def checkio(*args):
if not args:
return 0
return max(args) - min(args)
More
Hi, that `else` branch is redundant.
This is enough:
~~~~
def verify_anagrams(first_word, second_word):
first = first_word.replace(" ", "").lower()
second = second_word.replace(" ", "").lower()
for x in first:
if first.count(x) != second.count(x):
return False
More
A bit :)
1. Intstead of lines 7-9: `return "".join(result) == 'abcd...z'`
2. Look at [_sorted()_](https://docs.python.org/3/library/functions.html?highlight=sorted#sorted). It takes any iterable including __set__.
Refactored:
~~~~
import re
from string import ascii_lowercase
def check_pangram(t
More
Hi, this is inefficient. It builds list just for checking its length. This is much better:
sum(date(year, i, 13).weekday() == 4 for i in range(1, 13))
More
Hi, look at [_extended slices_](https://docs.python.org/3/whatsnew/2.3.html?highlight=extended%20slices#extended-slices).
More
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,
1. `[]` are redundant.
2. __bool__ is subtype of __int__ so you could write:
text = text.lower()
return sum(x in text for x in words)
\---+---/
|
bool
More
Hi, have a look at [__Counter__](https://docs.python.org/3.5/library/collections.html?highlight=counter#counter-objects).
More
Hi, you don't need math.pow. There's a power operator in python: **.
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