40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Nice, but I would shorten _eq_ a bit:
eq = lambda w: sorted(filter(str.isalpha, w.lower()))
More
Hi, look at _sorted()_. With sorted you can omit the _list()_ and the _output.sort()_. In fact you can _output_ completely and "feed_ _"".join()_ with sorted set.
More
Hi, the last `if` is redundant:
return len(al) == 26
Instead of lines 4-6 you can use _set comprehension_:
al = {x for x in text if x.isalpha()}
# or even:
return len({x for x in text if x.isalpha()}) == 26
More
Hi, `str_number` is __str__, so it's iterable
for i in str_number:
if i != '0':
answer *= int(i)
return answer
More
Hi, the last `if` is redundant, you can return the condition directly:
return 'boo' in stack
More
Hi, you can use _generator expression_ with _sum()_:
return sum(x in text.lower() for x in words)
More
Hi,
1. __str__ has _str.endswith()_ method.
2. `range(0, len(myList))` == `range(len(myList))`
3. but iterate the __list__ directly is better.
3. Finally: __set__ is iterable therefore you don't even need a list.
# You don't need my list
# You can't iterate the set directly
d
More
Hi, it's subjective but it would be nicer to repace lines 11-15 with a generator expression and sum:
return sum(cost(t[0]) for t in calldict.values())
More
Hi, __bool__ is subclass of __int__. You don't need all those nested `if..else`s, e. g.:
elif operation == "exclusive:
return x != y
More
Hi, you can use `*` operator to unpack `date1` and `date2`, e. g.:
d1 = date(*date1)
And
from datetime import *
is not a good practice.
More
Hi, bin() returns __str__, which has _str.count_ method, so you could write:
return bin(number).count('1')
More
Hi, you don't need `lambda`. _abs()_ is a function, so:
return sorted(numbers_array, key=abs)
is enough.
More
Hi,
1. the last `if...else` is redundant. You could return your condition after some changes.
2. Those `== False` tests are redundant.
More
Hi, you can do it without _math.pow()_. There's a power operator: __**__ (see [this](https://docs.python.org/3/library/stdtypes.html?highlight=binary%20operator#numeric-types-int-float-complex)).
More