40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, you could write _fibo_check_ like this:
def fibo_check(numb):
return numb in fibonacii(numb + 1)
1. The _if_ is redundant as numb in ch is already a boolean.
2. ch don't have to be a list as you could iterate over generator.
3. As you use _ch_ only once you could easily eliminate
More
Hi, I have two comments:
1. I hope, you've just forgot to remove the semicolon on line 3 :)
2. Look at _sum_ built-in function e. g.:
# Lines 5-8 you could replace with:
k = sum(array[::2])
# or the whole else block:
return sum(array[::2]) * array[-1]
# That's it :)
More
Hi, I have two comments:
1. In fact you don't need the else branch on line 11:
if len(data) < 10:
return False
# unindent the rest by one level.
2. On lines 4-9 you have three time the same pattern. You can extract the pattern and eliminate repetition.
You have:
if re.
More
Hi, on thing: _lambda_ and _map_ are redundant:
# You can join the phrases first which will result in one big string.
s = ','.join(phrases)
# And as s is a string you can directly call its replace method.
return s.replace('right', 'left')
# Finally: As you can chain
More
Hi, line 5 is useless as on the next line you assign a different value to _new_. In fact you can eliminate _new_ completely i. e. replace _new_ with _phrases_ on line 7.
More
Hi,
1. Don't use _sum_ as variable name it is a built-in function.
2. Look at _list comprehensions/generator expressions_ and _str.join()_.
More
Hi, look at _all()_ and _generator expressions_:
return all(x in text.lower() for x in ascii_lowercase)
More
Hi, do not redefine _sum()_:
# This is shorter, nicer and faster
f = sum(map(abs, groups))
# than:
sum = reduce(lambda x, y : abs(x) + abs(y), groups)
More
Hi,
1. look at _any()_:
def contain(s, need): return any(c in need for c in s)
2. look at _str.isupper()_, _str.islower()_, _str.isdigit()_.
More
Hi, you could write:
text = "".join(filter(str.islower, text.lower()))
More
Hi,
1. you certainly heard about _any()_.
2. As Veky already told you: You can omit [] and _sum()_ the __bool__`s`.
3. etc. ...
More
Hi, you don't need all those nested `if`s e. g.:
elif (operation == OPERATION_NAMES[4]):
return x == y
More