40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, you could use _sum()_:
return sum(chr(ord(pawn[0])-1)+str(int(pawn[1])-1) in pawns or
chr(ord(pawn[0])+1)+str(int(pawn[1])-1) in pawns
for pawn in pawns)
More
Hi, this is an anti-pattern:
if (x == 1 and y == 0) or (x == 0 and y == 1):
return True
else:
return False
# is equivalent to:
return (x == 1 and y == 0) or (x == 0 and y == 1)
More
Hi,
1. I see 4 lines ([one-linerized :)](http://www.checkio.org/mission/unlucky-days/publications/suic/python-3/one-liner/))
2. `calendar` isn't used.
3. You could write: `sum(cond for i in range(1, 13))` instead of `sum(1 for i in range(1, 13) if cond)`
More
Hi,
1. Use `and` not `&`.
2. You can use _all()_ instead of chaining _and()_.
More
Hi, what about:
return ','.join(phrases).replace('right', 'left') # instead of lines 2-4?
More
Hi, that `n + 1` is redundant. You could write:
if len(array) > n:
return array[n] ** n
else:
return -1
# or even:
if len(array) > n:
return array[n] ** n
return -1
More
Hi,
1. That `if...elif...elif` is redundant. Those are not special cases. The only special case is _empty list_.
2. Don't use semicolons in Python.
3. Those `B-E` variables are redundant. Why not?:
return sum(array[::2]) * array[-1]
More
Hi, [] and `...if...else` are redundant. E. g.:
return ''.join(w for w in text if w.isupper())
# or even:
return ''.join(filter(str.isupper, text))
More
Hi,
1. In `checkio` you can use list comprehension:
def checkio(data):
return [x for x in data if nrre(data,x) > 1]
# nrre is like str.count so
def checkio(data):
return [x for x in data if data.count(x) > 1]
More
Hi, _bin()_ returns __str__ and it has a _str.count()_ method, so you don't need that for loop:
return bin(number).count('1')
More
Hi, `value` is redundant. With a list comprehension and _len()_, or with _sum()_ it could be shorter and nicer.
More
Hi,
1. __str__ is immutable so it's not the best type in this case.
2. _filter()_ or generator expression + "".join() would be better, e. g.:
return filter(str.isupper, text)
More
Hi, don't reinvent the wheel. Look at _str.join()_:
return "".join(phrases).replace("right", "left")
More
Man... are you serious? But with a funny name it could be `Creative` solution? Anyway that last if is redundant:
return count == 26
# shorter:
import string
return all(x in text for x in string.ascii_lowercase)
More