28
Alex Mahotin
Last seen 3 hours ago
Member for 6 years, 1 month, 19 days
Difficulty Normal
Engineer (3D modelling, 3D printing).
Python math module has its own implemented gcd function, so you might drop out lines 4-7 and add one extra line with import.
Good reduce usage.
More
This solution would be speedy if given _values_ would've been a list instance.
Here you sort the given set at first and then convert it to a list which takes time.
More
I like your solution itself, it's very accurate IMO.
Can't say so about the comments. I understand your intention to make it clear for newbies but it works in reverse, leaving your code unclean.
Have a look at the lines 6, 7 or 3, 4 e.g.
Is there a need for such a comment? Code and comments ha
More
Since it's defined that 0 < xi, yi, r < 10, your way of data parsing works however it's not consistent for an arbitrary data value.
Probably it's better to use re.findall:
[x_1, y_1, x_2, y_2, x_3, y_3] = map(int, re.findall(r"\d+", data))
Or even consider this option:
(x_1, y_1), (x_
More
Good approach. A few things to point out at:
1.It's better to avoid naming variables "l" when possible because "l" is barely distinguishable from "1" (one).
2.It's possible to fold lines 3-7 into one using pythons ternary operator:
return data[(l // 2) - 1:(l // 2) + 1] if l % 2 == 0 else
More
I like numpy. Even though it works a bit slow (at least on my pc) - very convenient for matrixes handling.
More
Very concise and clear.
Perhaps, you might also consider .zfill method as an alternative to _" " * (mx-len(l))_
More
I leave aside str.translate() method and conversion a str into a set as I believe you have already seen those solutions.
You could inverse your solution logic and come up with something like this:
def isometric_strings(str1: str, str2: str) -> bool:
if len(str1) != len(str2):
More
Hi there,
I have several suggestions on how to improve your code and some tips which would help you in future=)
**The first part is about how your solution is looking.**
-Using _print_ for debug purpose isn't that bad, but leaving it in your code after debugging isn't good. It's cluttering the
More
We can use an analytical approach to solve this task with O(1) time complexity.
Pigeons count for every minute is 1, 3, 6, 10, 15 ...
Which is the triangular numbers sequence or **a(i) = (i+1)\*i/2**
Fed pigeons count for every minute is 1, 4, 10, 20, 35 ...
It's the tetrahedral number
More
Although this solution looks pretty short, using re is not a good idea in terms of resources.
Re engine is very greedy for such a purpose, which is even reflected in the [python doc](https://docs.python.org/3/howto/regex.html):
"Sometimes using the re module is a mistake. If you’re matching
More
_encrypted=encrypted+chr(ord(i)+delta+26)_
could be reduced to
_encrypted += chr(ord(i)+delta+26)_
More
.split method had been used to avoid an excessive using of the quotation marks or I missed something more important?
More
Hi!
I have a few thoughts on how you could improve your solution.
1. For lines 5-6. There is no need to find lenght of [intervals]. Here's a better way to check this.
_if not intervals:
return intervals_
2. For line 11. It could be reduced to _output = list(intervals[0])_.
3. For lines 1
More
Like it.
I solved this task in a similar way, but I didn't use intervals.pop(), this way initial data remains intact, which is better.
You might have [a look](https://py.checkio.org/mission/merge-intervals/publications/quarkov/python-3/simple-solution/) if you're interested
More