40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, you can shorten your code like this:
def checkio(data):
data.sort()
length = len(data)
if length%2 == 0:
return (data[int((length/2)-1)] + data[int(length/2)])/2
else:
return data[int((length-1)/2)]
More
Hi, the lambda superfluous. In this case you could write:
return sorted(number_array, cmp=abs)
More
It's impressive :) Some tips how to make it more "pythonic" (hopefully they'll be useful):
1. Check [PEP8](https://www.python.org/dev/peps/pep-0008/).
2. In python two empty lines are used instead of #--------------------
3. Make [docstrings](https://www.python.org/dev/peps/pep-0257/) from comments
More
Hi, in Python you can write this:
a, b, c = args
More
Hi, I've mentioned it in one of my previous comments: You don't need `lambda` in these cases:
return sorted(numbers_array, key=abs) # That's it :)
More
Hi,
1. Lines 1, 2 and 10 are pointless.
2. You could write `return array[n] ** n` and `return -1`.
More
Hi, instead of lines 2, 4-6 you can write this:
return sum(word in ltext for word in words)
More
Hi, consider the fact, that __str__ is immutable in Python. And look at _filter()_ function or _list comprehensions_/_generator expressions_.
# E. g.:
return "".join(filter(str.isupper, text)) # That's it :)
More
Hi, what about:
return sum(any(word in text_item for text_item in text.lower().split()) for word in words)
More
After I've read a few long threads under your solutions I have to say, that _lambdaphobia_ is a common phenomenon on CiO :)
More
Hi, a better way to solve it is to use str.isalpha.
To your solution:
1. This is unnecessary:
n = "0 1 2 3 4 5 6 7 8 9"
n = n.split()
# because str is iterable you can use this instead
n = "0123456789"
2. You can chain methods:
# so you can write
word.lowe
More
Hi, instead of:
if len(args) == 0:
...
you could write:
if not args:
...
More
Hi,
1. the last if is redundant:
return sorted(some2) == sorted(some1)
2. You do same things twice (once for first_word and once for second_word).
More
Hi,
1. ";" is unnecessary.
2. Do not reinvent the wheel: Look at [_str.join()_](https://docs.python.org/3.4/library/stdtypes.html#str.join).
More
Hi, let's have a look at your `get_bin` function:
```python
def get_bin(number):
return (list(map(int, list(str(bin(number))[2:]))))
```
1. `bin()` returns a __`str`__ => __`str`__ is redundant.
2. __`str`__ is iterable => `list` is redundant.
```python
def get_bin(number):
return list(map
More
Hi, why not?:
return sum(date(year, m+1, 13).weekday() == 4 for m in range(12))
More
Hi,
1. Last if is redundant:
return cmp(w1, w2) == 0
# or even:
return not cmp(w1, w2)
2. __str__ is iterable, so you dont' list lines 6, 8.
3. You do same things twice (once for w1 and once for w2).
4. You can use _sorted()_ instead of .sort().
P. S. Thanks for inspiration. Resul
More