40
Last seen 22 hours ago
Member for 9 years, 11 months, 3 days
Difficulty Advanced
Hi, one thing: _iter_ is a built-in so it shouldn't be used as a variable name.
More
Hi, you can use int.\_\_add\_\_ instead of lambda or you can:
import operator
return functools.reduce(operator.add, data)
but in fact _all you need is __sum___. :)
More
Hi,
1. You don't need the last if...else.
2. dight, upper, lower are booleans so why not:
return all((dight, upper, lower))
3. You don't _re_. Look at _str.isupper_, _str.islower_ and _str.isdigit_.
More
Hi, all if...else are redundant. You can directly return conditions or their negations.
More
Hi, if you've chosen _str.find_ intentionally, then it's an interesting creative solution.
More
Hi, a few things (maybe I could add them to the forum thread :/):
1. _else: pass_ is redundant, if branch is enough.
2. You can omit the _x_ variable and use _data_ i. e.
for i in data:
...
3. When you'll more comfortable with Python you can implement it in fancier way using _list
More
Hi,
1. == True is redundant.
2. List comprehension/generator expression or filter would be better here:
return "".join(lett for lett in text if lett.isupper())
# or:
return "".join(filter(str.isupper, text))
More
Hi, one of the list typical solution. Next challenge: Make it completely _if-free_ :)
More
Hi, I see that this is an older solution, but let me have comments:
1. You don't the _all_ variable, so line 4 is redundant.
2. Instead of assigning:
le = len(data) >= 10
# You should immediately return:
if len(date) < 10: return False
# when the password is to short is unn
More
Hi, you have three time the same pattern in your code, try to look at _all()_ or _any()_.
More
Hi, I have two comments:
1. Don't use "sum" as a variable name. This way you overrides a useful built-in function called [sum](https://docs.python.org/3/library/functions.html#sum).
2. _sum_ in action:
return sum(array[::2]) * array[-1] # and that's it
# and now you can remove lines
More
Hi, it's straightforward and easy to understand approach, but not quite pythonic. There are [built-in functions](https://docs.python.org/3/library/functions.html) like max() and min(), so you can replace lines 6-11 with:
return max(args) - min(args)
More
Hi, can write line 4 like this:
for w in words:
cnt += bool(text.lower().count(w))
More
Hi, when you first join the phrases, you can replace the words all at once:
return ",".join(phrases).replace('right', 'left')
More
Hi, as you don't use the index here:
for index, value_b in enumerate(sequence[index:]):
# you can write:
for _, value_b in enumerate(sequence[index:]):
More
Hi,
# Instead of this:
if len(queue) == 0:
continue
queue.pop(0)
# you could write this:
if queue:
queue.pop(0)
More
Hi, look at _str.isupper_, _str.islower_ and _str.isdigit_:
any(c.isupper() for c in data)
# instead of:
any(c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' for c in data)
etc.
More
Hi, look at slice in Python:
# You could write:
sum(array[::2])
# instead of:
sum(array[n] for n in range(0, len(array), 2))
More