20
Sergei
Last seen 10 months ago
Member for 4 years, 10 months, 12 days
Difficulty Normal
It's a smart idea to use 'hour' and 'minute' both for the `lambda` output and as an attribute name.
More
I guess, longer variable names can be used when there is much free space. Something like `s -> modified_code`, `c -> chars`, `m -> decoded_message`. Also the value of `m` can be formed this way:
`m = ''.join(map(MORSE.__getitem__, c))`
or this way:
`m = ''.join([MORSE[key] for key in c])`
More
The line with `return` keyword also can be written as `return len(line) == 1 or rc`. Also longer variable names would be nice because there is free space.
More
The idea of replacing upper characters with `'_' + char.lower()` is good, but I would implement the idea this way:
```python
def from_camel_case(name):
underscored = ['_' + x.lower() if x.isupper() else x for x in name]
return ''.join(underscored).lstrip('_')
```
Returning to your solution,
More
Probably `self.defense=0` is not necessary in `Rookie` and `Knight` `__init__` methods.
More
Sure, it is concise, but what if someone had to add a new validation? Or 10 new validations. And what about "Sparse is better than dense" from the Zen of Python?
More
Did you use capitalize() instead of upper() in order to show that capitalize() lowers all symbols except for the first one?
More
I guess the `isalive` is a little confusing - according to its name I had expected it returned whether a warrior is alive, but it makes an assignment instead it. I would name it `update_is_alive`. Also it seems that initially the `health` is the class attribute, but during a fight `health` instance
More
The approach is interesting. But what about `return True if count > 2 else False` into `return count > 2`?
More
Pretty thoroughly. But I guess it can be simplified. For example this way:
```python
def checkio(words: str) -> bool:
l=words.split()
for i in range(len(l)-2):
s=l[i:i+3]
if all([str.isalpha(one_of_three) for one_of_three in s]):
return True
return False
```
More
It seems that the code works well without `a.append(n)` and with `len(a)` instead of `len(a)/2`. However I am not sure, maybe there are reasons, e.g. to make the code more self-explanatory.
More
I guess this would work similarly:
```python
from collections import Counter
def frequency_sort(items):
r = []
counter = Counter(items).most_common()
for key, count in counter:
r.extend([key]*count)
return r
```
or this:
```python
from collections import Counter
def fr
More
Well done, but are you sure about positions of `x` and `y`? I mean `[g[3-x][y]` and `ciphered_password[y][x]`. Do `x` and `y` mean a row and a column, or they mean x and y axes?
More
Is the `TorF` list necessary?
```python
def checkio(words: str) -> bool:
wlist = words.split()
if len(wlist) < 3:
return False
else:
for w in range(2, len(wlist)):
if wlist[w-2].isalpha() and wlist[w-1].isalpha() and wlist[w].isalpha():
return
More
The `Warrior.hit` method is smart, but it seems that the `Warrior.get_attack` is not used. Also the repeating unit-to-unit `fight` is a thing to improve. I.e. maybe it would be better to remove `Warrior.fight` static method or to assign the static method to the global `fight` function this way: `fig
More
I guess, the `if` can be improved. Also it seems that there is no need to use indices instead of iterating through chars:
```python
def from_camel_case(name):
with_underscores = ''
for ch in name:
if ch.isupper():
with_underscores += '_'
with_underscores += ch
More
`self.font.join('[]')`, `self.append(vars(text).copy())` and `vars(self).update(version)` and are awesome.
But I would replace `def __init__(self): self.restore(dict(contents='', font=None))` with `def __init__(self): self.contents, self.font = '', None` as it is simpler. But it is probably less ed
More
I guess that this part:
else:
continue
is not necessary and can be removed.
More