40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi,
those `bool()` aren't necessary. You could write:
return bool(len(data) >= 10 and num.search(data) and upper.search(data) and lower.search(data))
# or even:
return len(data) >= 10 and all(x.search(data) for x in (num, lower, upper))
More
Hi, the `if...else...` is redundant:
return any(...) and any(...) and ... # is enough
More
Hi,
1. look at [_extended slices_](https://docs.python.org/3.5/whatsnew/2.3.html?highlight=extended%20slices#extended-slices).
2. `if not array:` is enough.
More
Hi,
1. You could write: `return w1 == w2`
2. __str__ is iterable => lines 2 and 3 are redundant.
More
Hi, look at [__(frozen)set__](https://docs.python.org/3.5/library/stdtypes.html#set-types-set-frozenset).
More
Hi,
if condition:
return False
else:
return True
is an antipattern. It's equivalent to:
return not condition
More
Hi,
1. __str__ is iterable => line 3 is redundant.
2. You could write `r *= i` instead of `r = i*r`.
3. `c` is redundant. You can use the list comprehension in for loop on line 6.
4. You could also solve it using _functools.reduce()_.
More
Hi, you could write:
if not array:
...
# instead of:
if len(array) == 0:
...
# and:
if array:
...
# instead of:
if len(array) != 0:
...
More
Hi,
1. Line 17 is redundant.
2. Instead of lines 13-17 you could write: `return c == 3`
More
Hi,
1. Line 3 is redundant.
2. You can nest method calls:
return ','.join(phrases).replace('right', 'left')
More
Hi,
1. This is an anti-pattern:
if condition:
return False
else:
return True
# You could write:
return not contdition
2. `True == 1` and `False == 0` so:
return not((not upp) or (not low) or (not dig))
# or shorter:
return upp and low and dig
More
Hi,
1. __str__ is iterable. You could write `alphabet = "abcde...xyz"`
2. or `from string import ascii_lowercase`.
More
Hi, look at [_enumerate()_](https://docs.python.org/3/library/functions.html?highlight=enumerate#enumerate) built-in.
More
Hi, all the nested `if`s are redundant. __bool__ is subclass of __int__. You could write e. g.:
elif operation == 'equivalence':
return x == y
More