40
Last seen 23 hours ago
Member for 9 years, 11 months, 3 days
Difficulty Advanced
Hi,
1. The `str` is completely redundant.
2. Don't use reserved words (e.g. `str`) as variable names.
Regards,
suic
```python
return ','.join(phrases).replace('right', 'left')
```
More
Hi, `lambda` is redundant as `abs` is a function (so `key=abs` is enough). Regards, suic
More
Hi, `...if...else...` is redundant:
```python
# bool
# /-------------------\
return True if len(set(elements))<=1 else False
# \--------------------------------------/
# bool
return len(set(elements))<=1
```
Regards,
suic
More
Hi, in normally when you have an `if ...: pass` or `else ...: pass` branch then there's something wrong with your code:
```python
def correct_sentence(sent):
if not sent[0].isupper():
sent = sent[0].upper() + sent[1:]
if sent[-1] != ".":
sent = sent + "."
return(sent)
`
More
Hi, you've actually implemented [`filter`](https://docs.python.org/3/library/functions.html#filter) with `map`. It's a nice misuse :)
```python
def find_message(text):
return ''.join(filter(str.isupper, text)
```
Regards,
suic
More
+5 for not using [fnmatch](https://github.com/python/cpython/blob/3.6/Lib/fnmatch.py)
More
Hi, next time let Python do the job for you (check [extended slices](https://docs.python.org/3/whatsnew/2.3.html?highlight=extended%20slices#extended-slices)). Regards, suic
More
Hi, check [`str.isupper()`](https://docs.python.org/3/library/stdtypes.html?highlight=isupper#str.isupper). The square brackets are redundant as `str.join` can consume generator expressions (check the [Glossary](https://docs.python.org/3/glossary.html)) too. Regards, suic
More
Hi, this is "absolute overkill" :) and not very Pythonic:
1. Python `str` has a `str.replace()` method and `in` is the pythonic way to check for substring. Therefore, lines 5 and 6 are redundant.
2. In Python you normally iterate directly over the index. If you need the element's index use the [`en
More
Hi, you can omit the `...if...else...` and replace `len(elements) == 0` with more Pythonic `not elements:
```python
def all_the_same(elements: List[Any]) -> bool:
return not elements or elements.count(elements[0]) == len(elements)
# \----------/ \-------------------------------------
More
A slightly reworked version is available [here](https://py.checkio.org/mission/friends/publications/suic/python-3/having-fun-with-tinus_trotyls-solution/). Thanks for inspiration :)
More
Hi, you can replace lines 21-25 and 28-32 with set-comprehension e.g.:
```python
return {
friend
for connection in self._connections if name in connection
for friend in connection if name != friend
}
```
Regards,
suic
More
```python
# redundant
# +-------------------------------------+
# | |
# V V
return max([(data.count(x), x) for x in set(data)])[1]
# \---------------------------------------
More
Hi, this is nice and correct :)
P.S.: A more codegolfish version of `append_dot`: `lambda s: s+"."*(s[-1]!=".")`
More
Hi, `import re` is redundant. You can use `str.strip()` instead of that regex. Regards, suic
More
2-lines == too long :)
Regards,
suic
P.S.: See [this](https://py.checkio.org/mission/unlucky-days/publications/suic/python-3/przemyslawdaniels-2-liner-one-linerized)
More