40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi, this is redundant:
if data.count(x) == 1:
continue
Why not:
if data.count(x) > 1:
z.append(x)
More
Hi,
1. That `if...elif...elif` is redundant. Those are not special cases. The only special case is _empty list_.
2. Don't use semicolons in Python.
3. Those `B-E` variables are redundant. Why not?:
return sum(array[::2]) * array[-1]
More
Hi, that `n + 1` is redundant. You could write:
if len(array) > n:
return array[n] ** n
else:
return -1
# or even:
if len(array) > n:
return array[n] ** n
return -1
More
Hi, this is the same:
return firstWLcCounterList == secondWLcCounterList
is the same as:
if firstWLcCounterList == secondWLcCounterList:
return True
else:
return False
More
Hi,
1. Look at __Counter__ from `collections` module.
2. Instead of lines 13-16 you could write this:
return sorted(counterList, key=lambda x: x[1], reverse=True)[0][0]
3. Instead of `alphabet` you could import `ascii_lowercase` from `string` module.
More
Hi, this is not pythonic. Look as _list comprehensions_. Again: Those `print`s are useless.
More
Hi,
1. code from line 5 is redundant.
2. you don't need _re_. There is _str.isdigit()_ method.
3. you don't need `...if...else...` as you could use _bool()_ instead or, when you replace that _re_ with _str.isdigit()_ you can simply remove it.
More
... two thumbs, but those [] on line 59 are redundant :)
More
Hi, __bool__ is subtype of __int__, so you don't need those nested ifs and inner functions. For example:
def equivalence(x, y):
return x == y
# or:
equivalence = lambda x, y: x == y
More
Hi,
1. you don't need `[]` as _sum()_ accepts generator expressions.
2. you don't need _list()_ as _bin()_ returns __str__, which is iterable.
3. instead of _int()_, you could simply `sum(i == "1" ...)`.
4. in fact you don't need _sum()_ at all. Upon closer inspection, that `sum()` from no. 3. is s
More
Hi,
1. That `for i in text:` is useless.
2. You don't need `[]` in _str.join()_.
3. Look at _filter()_.
More
Hi, look at _sum()_ and _generator expressions_:
sum(i in text.lower() for i in words)
More
Hi, this is an overkill:
1. Look at _extended slices_ e. g. `array[::2]`.
2. After some clean-up:
def checkio(array):
if array:
evens = []
for i, v in enumerate(array):
if i % 2 == 0:
evens.append(v)
return sum(evens) * array[-1]
ret
More
Hi,
1. Line 5: `if not u: return []`
2. You don't need __Counter__.
3. Look at other solution, which use simple list comprehension.
More
Hi,
1. that last `if...else` is redundant, you can directly return your condition.
2. or you can move that if inside the for loop:
if ...:
for ...:
...
if n and u and l:
return True
return False
More
Hi, line 2 is redundant as `arg` is iterable, you don't need to convert it to a list.
More