40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
Empty array is treated as false, so you can write:
if not array: return 0
And also:
array[0::2] == array[::2]
so you can omit the 0.
More
Hi, the lambda superfluous. In this case you could write:
return sorted(number_array, cmp=abs)
More
Hi, why not:
return (game_result[0][0]==who and ...)
That `if...else` is redundant.
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, 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, what about:
return sum(any(word in text_item for text_item in text.lower().split()) for word in words)
More
Hi, that `if` is redundant:
return (pattern, command) in [(42,"12a0b3e4"), ...]
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,
1. You don't need == True as _str.isupper()_ return True
2. Look at _str.join()_ and _generator expressions_:
return "".join(i for i in text if i.isuppper)
# filter is even better for this:
return "".join(filter(str.isupper, text))
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, 3 little things:
# connection = (connection, ) is redundant
self.connections += (connection, )
# lambda in line 23 is redundant:
return reduce(set.union, self.connections)
# change self.connection to list as self.connection is mutable e. g.:
self.connections
More
Hi,
1. the last `if...else` is redundant. You could return your condition after some changes.
2. Those `== False` tests are redundant.
More
Hi,
1. Instead of `t == t.upper()` you could use `t.isupper()` With _str.isupper()_ you can omit the `t.isalpha()` check.
2. `t` is already __str__ so _str()_ on lines 4 and 5 is redundant.
result += t
3. Look at _filter()_ built-in.
4. __str__ is immutable type, therefore is not the best jo
More