40
Last seen 22 hours ago
Member for 9 years, 11 months, 3 days
Difficulty Advanced
You like typing :)
import re
VOWELS = "[AEIOUY]"
CONSONANTS = "[BCDFGHJKLMNPQRSTVWXZ]"
r = re.compile(r'\A({0}?({1}{0})*{1}?){2}\Z'.format(VOWELS, CONSONANTS, '{1}'), re.I)
def checkio(text):
return sum(bool(len(w) > 1 and r.match(w)) for w in re.split(r'
More
Hi, instead of lines 14-17 you could write:
return brackets == []
# or
return not brackets
More
Hi, this is "obfuscative". Why not:
return [d for d in data if data.count(d) > 1] # ?
More
Hi,
`if x == '0': continue` is redundant. Why not:
if not x == '0':
count *= int(x)
More
Hi,
1. Instead of `t == t.upper()` you could use `t.isupper()` With _str.isupper()_ you can omit the `t.isalpha()` check.
2. `t` is already __str__ so _str()_ on lines 4 and 5 is redundant.
result += t
3. Look at _filter()_ built-in.
4. __str__ is immutable type, therefore is not the best jo
More
Hi,
1. Why not?:
if len(array) > 0:
# or even:
if array:
# and:
for i in array[::2]:
# instead of
for i in array[0: len(array): 2]:
2. Look at _sum()_:
# sum of even elements:
sum(array[::2])
More
Hi,
1. Look at _divmod()_.
2. Look at [this](https://docs.python.org/3.4/library/stdtypes.html#truth-value-testing).
def checkio(number):
multiple=1
while number:
number, digit = divmod(number, 10)
if digit: multiple *= digit
return multiple
More
Hi, _bin()_ return __str__ so `str(bin_num)` is redundant. As `bin(number)` is a __str__ you can use _str.count()_ method.
More
Hi,
1. _max()_ and _dict()_ are a built-in functions.
2. Look at _sorted_, e. g.: `alpha = sorted(dict)`
3. Even if Python's exceptions are not expensive, lines 2-9 are quite ugly.
4. Look at __collections.Counter__.
I've played with your code. Result is [here](http://www.checkio.org/mission/most-
More
Hi, it's kinda verbose:
1. `== None` is redundant.
2. You can use _all()_ instead of those `if`s.
3. In each if condition you have the same pattern.
return all(re.search(rgx, d) for rgx in ("^.{10,}$", "[0-9]+", "[a-z]+", "[A-Z]+"))
More
Hi, it's inefficient, and not as clear as it could be:
return "".join(phrases).replace('right', 'left')
More