40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
```python
def index_power(array, n):
if len(array) > n:
return array[n] ** n
return -1
```
More super? :)
More
Hi, interesting approach :) Below is a slightly refactored version. I'm too lazy to give a detailed description so I highlight only two things:
1. Check [this page](https://wiki.python.org/moin/TimeComplexity).
2. There's no need to store a list of lists in `li` as you only need its length.
Regard
More
Hi,
You can replace lines 1-6 with:
numbers = map(int, str(number).replace('0', ''))
Regards,
suic
More
Hi,
gondolom ma mar igy irnad: `sum(array[::2])` :)
Regards,
suic
P. S.: A codewarsbol komolyan elegem lett. Februar ota nem jatszom. Ami a [kerdesedet](https://www.codewars.com/kata/57b971f68f58135e840001cc/discuss#58ff5dc2588521f39c00003d) illeti: Szerintem [ez](https://hu.wikipedia.org/wiki/B
More
Hi, `lambda` is redundant. `key=abs` is enough. Regards, suic
More
Hi, you can avoid constructing the list just for checking its length buy replacing `len(list(g))` with this
sum(1 for _ in g)
As I remember, @veky gave me this advice long time ago.
Regards,
suic
More
Alternative:
```python
return not bool(elements) or len(set(elements)) == 1
```
Regards, suic
More
Hi, that if is redundant:
return eval(OPERATION_NAMES[operation])
# or even:
boolean = lambda x, y, op: eval(OPERATION_NAMES[op])
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
Hi, `lambda` is redundant as `abs` is a function (so `key=abs` is enough). Regards, suic
More
Hi, sorted data is redundant. `sorted()` returns a list which you slice. Regards, suic
```python
return sorted(data, key=lambda x: x['price'], reverse=True)[:limit]
```
More
Hi, you don't need the list comprehension:
```python
sum(word in text.lower() for word in words)
```
Regards,
suic
More
Hi, this code is quite verbose and not very pythonic. Check the official [documentation](https://docs.python.org/) especially
1. [Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing) and
2. [Boolean Operation](https://docs.python.org/3/library/stdtypes.html#boo
More
Hi,
`lambda` is redundant as `abs()` is taking one argument and functions are first class citizens in python: `return sorted(numbers_array, key=abs)`.
Regards,
suic
More
Hi,
```python
text = text.split(' ') # This splits the string by spaces.
text[0] = text[0].capitalize() # can be replaced with text[0].upper()
text = (' ').join(text) # the first paren in redundant
if text[-1] != '.': # not pythonic. There's the str.endswith
More
Hi, interesting approach. The 0 on line three is redundant. Regards, suic
More
Hi, you could use `sorted()` instead of `list.sort`:
```python
return sorted(data, key=itemgetter('price', 'name'), reverse=True)[:limit]
```
Regards,
suic
More