40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, I have a few comments:
1. (a + b + c == len(password)) is redundant.
2. Once a, b and c are greater than 0 you can return:
# so:
...
if d in string.digits: c+= 1
if c > 0 and b > 0 and a > 0: return True
return False
3. Instead of lines 4-6 you can write this:
More
Hi, I have three comments:
1. Don't use _sum_ as variable name. It's a built-in function.
2. Look at list comprehensions and generator expressions.
3. Look at _str.join_.
Join and generator expression in action:
return "".join(char for char in text if char.isupper())
More
Hi,
1. if..else is redundant as you return your condition.
2. You can shorten you condition using generator expression and _all()_ or _any()_.
More
Hi, this is little bit "re-inventing the wheel", look at _bin()_.
More
Hi, `[2:]` is redundant as the first two characters are `0b`, which won't change the `.count('1')`.
More
Hi,
1. Look at _str.endswith()_.
2. Look at `operator` module.
3. In this a _generator expression_ or list comprehension would be faster than _map()_ and IMHO cleaner:
[x != y and len(x) > len(y) and x[-len(y):] == y for x, y in itertools.product(words_set, words_set)]
More
Hi,
1. _list()_ is redundant.
2. You could use `&` operator for set intersection.
More
Hi, lambda is redudant. _abs()_ is a function:
return sorted(numbers_array, key=abs) # pay attention that it is abs and not abs()
More
Hi,
1. You don't need the `result` variable.
2. Look at _all()_, e. g. you can write this instead of line 8:
if all(j.isalpha() for j in wlist[i:i+3]):
3. You don't need that `else` branch.
4. Look at _any()_. Using it you can refactor lines 3 and 6-10 like this:
return any(all(j.is
More
Hi,
1. all those inner `if...else`s are redundant, e. g.:
return not (x == 1 and y == 0) # for lines 13-16
2. you don't have to enumerate the cases. Just use `or`, `and` and `not` built-ins and `==` and `!=` operators.
More
Hi,
1. `== True` is redundant as _str.isupper()_ returns __bool__.
2. __str__ is immutable, therefore it is not the best type for accumulation.
3. Last but not least __str__ is _iterable_ so you could write:
for i in text:
if i.isupper():
word += i
# or even better
More
Hi, you don't need all those internal `if...else`s e. g.:
if operation == "equivalence":
return x == y
More