40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
1. You could write: `friday13 += (date(year, month, 13).isoweekday() == 5)`.
2. Look at _sum()_.
More
Hi, look at [__(frozen)set__](https://docs.python.org/3.5/library/stdtypes.html#set-types-set-frozenset).
More
Hi, the `if...else...` is redundant:
return any(...) and any(...) and ... # is enough
More
Hi,
those `bool()` aren't necessary. You could write:
return bool(len(data) >= 10 and num.search(data) and upper.search(data) and lower.search(data))
# or even:
return len(data) >= 10 and all(x.search(data) for x in (num, lower, upper))
More
Hi,
1. All `== True` checks are redundant.
2. All `else` branches are redundant.
3. Finally: When you use _any()_ with `and` or _all()_ all the `if`s are redundant.
Your code after step 2.:
def checkio(data):
if len(data) >= 10 :
if any(c.islower() for c in data):
if
More
Hi, I have a two comments:
~~~~
# 1)
return cond
# is the same as:
if cond:
return True
else:
return False
# 2) You can shorten is_palindrome like this:
def is_palindrome(text):
return text == text[::-1]
More
Hi, this is better :)
I would make a slight change: Assign this `text[i:j]` to a variable e. g.:
def longest_palindromic(text):
pal = ''
for i in range(len(text)):
for j in range(i, len(text)+1):
subst = text[i:j]
if len(subst) > len
More
Hi, look at [_extended slices_](https://docs.python.org/3/whatsnew/2.3.html?highlight=extended%20slices#extended-slices).
More
Hi, this is inefficient because __str__ is immutable i. e. each `result += char` creates a new string. You could use:
1. [_filter()_](https://docs.python.org/3/library/functions.html?highlight=filter#filter) or [_generator expression_](https://docs.python.org/3/whatsnew/2.4.html?highlight=generator
More
Hi,
1. _list()_ is redundant. [_filter()_](https://docs.python.org/3/library/functions.html?highlight=filter#filter) returns an _iterable_ which [_str.join()_](https://docs.python.org/3/library/stdtypes.html?highlight=join#str.join) can consume.
2. __str__ has [_str.isupper()_](https://docs.python
More
Hi, all the `if`s are redundant:
~~~~
# as:
if cond:
return True
else:
return False
# is the same as:
bool(cond) # when the condition is itself a bool than bool() is redundant
# and:
if cond_a:
if cond_b:
...
# is the same as:
if cond_a and cond_b:
...
# ------------
More
Hi, you could write:
1. `return not len(alphabet) > 0` instead of lines 7-10
2. `alphabet = list(string.ascii_lowercase)`
3. `text = text.lower()`
More
Hi, you don't need math.pow. There's a power operator in python: **.
More
Hi, few tips:
1. It's better to put the whole expression in parentheses instead of using ugly backslashes.
2. `and` is short circuiting.
3. Look at the _all()_ built-in function.
4. and combine it with a generator expression.
See my [refactored version](https://checkio.org/mission/house-password/p
More
Hi,
1. _list()_ is a built-in function, don't use it as variable name.
2. Look at list comprehensions.
More
Hi,
instead of the condition on line 6 you could write:
sum(i.isdigit() for i in data)
# or even better
any(i.isdigit() for i in data)
Other option is to combine _sum()_ and _filter()_
sum(filter(str.isdigit, data))
More