22
Last seen 5 years ago
Member for 8 years, 4 months
Difficulty Normal
Would like to receive comments/critics of my published solutions.
Instead of manually flooring each result of a division with /, there's a much simpler way - using floor division with //. For example:
data[len(data)//2]
More
`get_size` is trying to grow every existing cell into a healthy colony. If successful, it returns the size of colony, otherwise (unhealthy colony is grown) returns zero.
More
If you want shorter, lines 3 and 7 could be a bit shorter:
sorted(args if len(args[:-1]) else args[0], ...
For even shorter, take a look at [my solution](https://py.checkio.org/mission/min-max/publications/narimiran/python-3/minmax/) ;)
More
You could have avoided duplicated code in two branches depending on the length of `args` with something like this:
input_ls = args if len(args) > 1 else args[0]
Now lines 3-13 and 29-39 are not needed.
More
Why didn't you use the same logic for `max` as you did for `min`, with the only difference that you pass `reversed=True` as another argument to the `sorted` function?
More
Lines 7 and 8 - the first triangle from the input is always used as a starting point, only others are permuted.
More
Line 4 is easy to write manually when you have only three numbers, but what if you had more?
Take a look at `itertools` module, it is very useful in many situations.... (here you could have used `itertools.permutations(range(3), 3)` ).
More
Most of the code is duplicated in both functions - you could have used a helper function, which would be called from each function (at least for lines 2-7 and 14-19, if not even more).
More
There is a `hypot` function in the `math` module, that could have been more elegant than your line 4.
Line 13 would look like this:
else: replace = hypot(*subtract(pre, cur)) < hypot(*subtract(pre, nex))
More
Line 29 - even without `key`, `data` will be sorted by the first element then by the second.
More
Line 4, more elegant way to see if string ends with some characters would be:
subj.endswith('!!!')
More
Instead of: `if not any(s for s in subj if s.islower())`, it would be easier just to check:
if subj.isupper()
Also, you can get rid of line 10 comment, if on line 11 you use a string method that is self-describing:
if subj.endswith('!!!')
More
Nice idea to limit the range just to the half of the length of the data (line 6)!
More
Some nice ideas here (hence upvotes), but not as speedy as I expected from a solution in this category (hence only two upvotes :))
More
Lines 8-11 could/should be more pythonic if written as one line, by replacing `if` with `return`:
return subj.isupper() or subj[-3:] == '!!!' or any(word in ...
More
I took some liberty and refactored your solution:
Lines 4 and 6 can be checked with one `if` statement.
Line 9 is not needed if we use `subj.lower()` on line 10.
`reps` is always 1, so it is not needed.
Line 12: `join` accepts generator - no need to create a list (use `[` and `]`). It seems t
More
Line 7: `total = sum(users.values())`
Line 12: `while nodes:`
Lines 18-20: `next` is a Python keyword, you should't use it as a name for your variables.
More
Line 9 - why joining a split subject when you can just use the original one with `if subj.isupper()`? ;)
More
Instead of importing `chain` and creating a set `all_nodes`, wouldn't it be easier just to change the line 15 to:
disocnnected = users.keys() - connected
More
Lines 7-10: more pythonic way of iterating is by directly iterating through elements, not indices:
def customSet(word):
tmp = [word[0]]
for c in word[1:]:
if c != tmp[-1]:
tmp.append(c)
return "".join(tmp)
Line 14 is not needed.
Lines 15 and
More