40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, you could write:
# empty array as treated as false:
if not array:
return 0
# total is redundant:
return sum(array[::2]) * array[-1]
More
Hi, that `== True` is redundant:
if sub in text.lower():
total += 1
Tip: Look at _sum()_ and _generator expressions_.
More
Hi, there's so much in your code:
1. The last `if` and all those `== True` checks are redundant.
2. You perform all the checks for every element, which is not necessary.
3. If `data` is too short, you can immediately return.
4. That "create list from string exercise" on lines 6-10 is unnecessary. _
More
Hi, `ch.isupper()` returns a __bool__ therefore `== True` is redundant. You could safely omit it.
More
Hi,
1. `character` is __str__ so _str()_ is redundant.
2. Look at _filter()_ and _str.join()_.
More
Hi, this is a good example, how you could make your code hard to read by adding comments. Good practice is to indent your comment and keep them short or wrapped.
Sorry but some of those comments are ridiculous.
Btw: Look at _docstrings_.
E. g.:
def checkio(data):
"""
The 'chec
More
Hi, I have a few comments.
1. You could write `if y != 0:` instead of `if not (y == 0):`.
2. You could write `result *= y` instead of `result = result*y`.
3. Look at _list comprehensions_.
More
Hi, you could write:
def checkio(words_set):
for w1 in words_set:
for w2 in words_set:
if w1 != w2 and w1.endswith(w2):
return True
return False
or you could use _any()_ with _generator expression_.
More
Hi, all those nested if's are redundant. __boo__ is subclass of __int__. E. g.:
elif operation == "equivalence":
return x == y
More
Hi, that last `if` is redundant:
for i in new_word:
if i.isalpha():
count +=1
if count == 3:
return True
return False
More
Hi, this
if count < 26:
return False
else:
return True
is a newbie antipattern.
return count == 26 # is enough.
Look at `string` module. It contains e. g. the `ascii_lowercase` constant.
More
You can use str.count() to check the number of occurrences of a string in other string. Check help(str) in you python interpreter to check out usefull string methods.
More
Hi, in Python ([Truth Value Testing](https://docs.python.org/2/library/stdtypes.html#truth-value-testing)):
False == () == '' == []
so you can replace this:
if args == () or args == '' or args == []:
with this:
if not args:
More
Hi, I have a few comments:
1. String methods:
data == data.upper() is the same as data.isupper()
data == data.lower() is the same as data.islower()
2. You can use [__any__](https://docs.python.org/3.4/library/functions.html?highlight=any#any) instead of long if..elif...else.
3. Condition
More
You don't need to use lambda in this case:
key=abs
is the same as
key=lambda x: abs(x)
More