40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Two small things:
1. You can directly rename the argument i. e.
def checkio(password):...
2. The if clause is not necessary. You can replace:
if :
return True
else:
return False
with:
return
More
1. See my comment about ifs to your solution of House Password
2. Shorthand:
a = a + 1
the same as
a += 1
Try to look at [assignment operators](http://www.tutorialspoint.com/python/python_basic_operators.htm). :)
More
It's a matter of taste but: This is more __noisy__ than clear, especially these boxes from # and the print statement are really not necessary.
This
# return sum(array[0::2])* array[-1]
is quick and clear.
It would be clear enough to add a long comment explaining what [0::2] and array[
More
You can remove this:
if number>0 and number <= 1000:
else:
None
The is enough as all the tests meet this condition.
More
Why should this be called "most readable style"? :)
Now in a more constructive way:
1. Have you heard about [PEP8](https://www.python.org/dev/peps/pep-0008/) or some "linters" e. g. [pylint](http://www.pylint.org/)? ([online PEP8 check](http://pep8online.com/))
2. The backslashes are not necessary
More
May I suggest?
(data.isalnum() != True) == not data.isalnum()
When you want split an expression to multiple lines just but it parentheses as there can be line breaks inside parentheses. E. g. this is valid code:
([1,2,3,4,5,6],
[9,5,6,7,8,9])
More
Hi, look at _extended slices_ (`array[::2]`) and _negative indices_ (`array[-1]`).
More
Hi, look at `//`, e. g.:
number = number // 10
# or even:
number //= 10
# or:
number, n = divmod(number, 10)
a.append(n)
More
Hi,
1. _bin()_ return __str__ so _str()_ on line 2 is redundant.
2. You don't need `b`.
3. You don't need the for loop, as there's a _str.count()_ method.
More
Hi,
1. `first` and `second` are strings so _str()_ is redundant.
2. Look at _list comprehensions_ and _generator expressions_ or _filter()_:
result = [word for word in b if word in a]
result = filter(a.__contains__, b)
# or even:
return "".join(sorted(filter(a.__contains__,
More
Hi,
1. `sequence` is iterable, so line 6 is redundant.
2. Look at _enumerate()_.
3. `range(0, len(a)) == range(len(a))`
count = 0
for i, x in enumerate(sequence):
for y in sequence[i:]:
if x > y:
count += 1
return count
# or with sum() and
More