40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi, if...else is redundant:
return len(set(filter(str.isalpha, text.lower()))) == 26
More
Hi, you can avoid the else if :)
return len(array) and return array[-1]*sum(array[::2])
More
Hi, you can unpack the _date1_ and _date2_ tuples with *.
d1 = date(*date1)
d2 = date(*date2)
More
Hi, there's an alternative approach. _str.join()_ first and then use _str.replace()_.
More
Hi, you don't need to sort the words => _sorted()_ is redundant.
You can use a more functional approach:
return sum(x in text.lower() for x in words)
More
Hi, this is reinventing the wheel. Look at _str.islower()_, _str.isupper()_, _str.isdigit()_.
More
Hi, why generator expression? When you first join, then you can use _str.replace()_.
More
Hi, _bin()_ return __str__ and it has __str.count()_ method, try to apply it on this case.
More
Hi, extract the pattern from line 4, 5 and make it a function:
f = lambda w: collections.Counter(w.replace(' ', '').lower())
return f(first_word) == f(second_word)
More
Hi, fwx and swx are redundant.
f = lambda w: Counter(w.replace(' ','').lower())
return f(first_word) == f(second_word)
More
Hi, don't use "\\" if it's not necessary. Put your expression in () instead e. g.:
grid = ([tuple([0]) * (len(grid[0]) + 2)]
+ [tuple([0]) + i + tuple([0]) for i in grid]
+ [tuple([0]) * (len(grid[0]) + 2)])
There are redundant [] on the last line:
return sum(
More
Hi,
1. The last if is redundant and the == True tests are redundant.
return value1 and value2 and value3 and value4
# or
return all((value1, value2, value3, value4))
2. If the len(data) < 10 then it does not make sense to compute the rest, it's better to return immediately.
More
Hi, the last if is redundant:
return lengthCheck and digitCheck and upperCheck and lowerCheck
In fact, all the if's are redundant, but I don't want to go so far :)
More