22
Last seen 5 years ago
Member for 8 years, 4 months
Difficulty Normal
Would like to receive comments/critics of my published solutions.
You could/should replace lines 4 to 7 with:
return sorted(first_word) == sorted(second_word)
More
Instead of the function `o`, you could/should have used built-in function `round` - it would have saved you some trouble.
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
You might want to explore Python's method `count` that you can use on the lists. It might have saved you a lot of trouble here.
More
You might want to explore Python's method `count` that you can use on the lists. It might have saved you a lot of trouble here.
Also, there's no need for your line 20 - you could/should just `return my_list`.
More
for i in range(len(num)):
if num[i]!=0:
ans = ans * num[i]
More pythonic way of this would be:
for n in num:
if n != 0:
ans *= n
More
You should avoid naming your variables as python keywords, in this case - `list`.
More
You might want to check Python's `sorted` function, it has a `key` argument which would have been very useful here.
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
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
There's a built-in function `bin` to convert numbers to binary, no need for reinventing the wheel ;)
More
You can directly pass the `abs` function, without a need for lambda, just: `key=abs` :)
More
You can directly pass the `abs` function, without a need for loving lambda, just: `key=abs` :)
More
The solution would be more elegant if we were allowed to return only one of the most critical points:
return min(users.keys(), key=subnetworks)
More