40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, this is all but pythonic. Try to look at for...else.
P. S.: I've played with your code. Result is [here](http://www.checkio.org/mission/house-password/publications/suic/python-3/with-forelse/).
More
Hi, I would say: Definitely more complicated than it has to be be :D
E. g. those lambdas are redundant:
conditions = [str.isupper, str.islower, str.isdigit]
Tip: Look at _all()_, _any()_ and _generator expressions_.
More
Hi, why not `reduce(bool.__and__, ...)`? Why not ___all()___? Yes, you don't need that lambda.
More
Hi, you could use _set comprehension_:
def check_pangram(text):
R = {letter for letter in text.lower() if letter.isalpha()}
return len(R)==26
# and finally get rid of R:
def check_pangram(text):
return len({letter for letter in text.lower() if letter.isalpha()}
More
Hi,
1. Line 2 and 7 are pointless. You don't need to declare `i`. Assigning `B` to `data` does nothing. Why don't you return `B`?
2. You don't need `B`:
B = [i for i in data if data.count(i) > 1]
# data = B # per 1. is pointless
# return data # per 1. is pointless
retur
More
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