22
Last seen 5 years ago
Member for 8 years, 4 months, 15 days
Difficulty Normal
Would like to receive comments/critics of my published solutions.
Line 29 - even without `key`, `data` will be sorted by the first element then by the second.
More
Instead of returning `i + 1` (line 6), you could have passed `1` as a second argument to the `enumerate` function (line 4), which is a starting index (the default value is 0), and then return just `i`, which is more elegant.
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
Lines 7 and 8 - the first triangle from the input is always used as a starting point, only others are permuted.
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
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
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
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
`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
In the function `is_triangle`, instead of three ifs for different cases, it might be better to sort the values and just compare two smallest with the largest one, for example:
def is_triangle(a, b, c):
a, b, c = sorted(a, b, c)
return a + b > c
More
Instead of the function `o`, you could/should have used built-in function `round` - it would have saved you some trouble.
More
There's a built-in function `bin` to convert numbers to binary, no need for reinventing the wheel ;)
More
There's a built-in function `bin` to convert numbers to binary, no need for reinventing the wheel ;)
Also:
for i, j in enumerate(nb):
if j != mb[i]:
you might want to use `zip` in the future:
for n, m in zip(nb, mb):
if n != m:
More
for i in range(len(binN)):
if binN[i] != binM[i]:
Instead of this, more Pythonic way would have been:
for n, m in zip(binN, binM):
if n != m:
More
You might want to check Python's `sorted` function, it has a `key` argument which would have been very useful here.
More
You can directly pass the `abs` function, without a need for loving lambda, just: `key=abs` :)
More
You can directly pass the `abs` function, without a need for lambda, just: `key=abs` :)
More
You should avoid naming your variables as python keywords, in this case - `list`.
More