16
Last seen 3 years ago
Member for 4 years, 10 months, 28 days
Difficulty Normal
There's no need in `else:` on the 6th line, it doesn't improve readability. You can even put `index + 1 < len(values)` as condition for `while` loop instead of `True` and get rid of the `if...break` completely.
More
data[len(data)-1]
can be replaced with
data[-1]
and
if len(data) > 1:
with
if data:
More
You don't actually need that `p` variable, you can use the last element of the `answer` (`answer[-1]`)
More
It'd be better to put 4th line into
if __name__ == '__main__':
statement body
More
Probably it'd be more Pythonic to write `c, v = 0, 0` instead of `c = 0; v = 0`.
Names `v` and `c` do not describe purpose of these variables. BTW you can safely replace these variables with a single variable.
You don't need `c = 0; v = 0` on line #13, these vars are already contain zero.
Given
More
https://www.python.org/dev/peps/pep-0008/
> Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier:
>
> # Correct:
> def f(x): return 2*x
>
> # Wrong:
> f = lambda x: 2*x
>
> The first form means that the name of
More
`ans=ans+...` can be safely replaced with `+=...`
To return `True` or `False` you don't need `if-else` in `vow` function, you can return `x[y][z] in VOWELS`.
`def vow(x,y,z):` is not readable, I'd write something like `def is_vowel(words, word_index, char_index):`.
Note that you don't actually ne
More
No need in `else: pass` branch (lines 9-10).
You can get rid of `if` statement on lines 11-12 just by including 0 in for loop's range (line #3) – just use `-1` instead of `0` for `stop` parameter. BTW you can use `reversed(range(33))` for this purpose.
More
You can get rid of appending `1` on the 6th line if you change loop condition (3rd line) to `while number != 0:` (or even to `while number:`).
Same goes for reversing the string: just prepend instead of appending (`binary = str(number % 2) + binary` on the 3rd line).
More
no need in conversion to `str` for value returned by `bin`, it already returns `str`
More
Please, use some spacing around operators to increase readability of your code (see more about general coding style recommendations in [PEP-8](https://www.python.org/dev/peps/pep-0008/#other-recommendations)), e.g. `count += 1` is more readable than `count+=1`.
If you change loop's condition (line
More
I have only some style-related notes
according to [PEP-8](https://www.python.org/dev/peps/pep-0008/#comments):
> Block **comments generally apply to** some (or all) **code that follows them**, and are indented to the same level as that code.
BTW comments in English are preferred (even though I kn
More
https://www.python.org/dev/peps/pep-0008/
> Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier:
>
>
>
> # Correct:
> def f(x): return 2*x
>
> # Wrong:
> f = lambda x: 2*x
>
> The first form means that t
More
I guess `return "." not in line and len(set(line)) == 1` is more readable than explicitly specifying `True` and `False` values. BTW you don't need to convert `set` to `list` here as well, `set` implements `__len__` method so `len` function can be applied to `set` instances.
I'd replace repeated use
More
You can rewrite
```python
if phrase[i+c] == " ":
d += phrase[i+c]
elif phrase[i+c] in VOWELS:
d += phrase[i+c]
c += 2
else:
d += phrase[i+c]
c += 1
```
as
```python
d += phrase[i+c]
if phrase[
More