I have a one line. For this line I have start and end point. Now I want to split this line into multiple lines or number of points. How to do that?
The line looks likes below ..
Any idea?
You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python. You can use it to join text on separate lines and create a multiline string.
Click in a cell, or select multiple cells that you want to split. Under Table Tools, on the Layout tab, in the Merge group, click Split Cells. Enter the number of columns or rows that you want to split the selected cells into.
To split long commands into readable commands that span multiple lines, we need to use the backslash character (\). The backslash character instructs bash to read the commands that follow line by line until it encounters an EOL.
Python solution:
def split(start, end, segments):
x_delta = (end[0] - start[0]) / float(segments)
y_delta = (end[1] - start[1]) / float(segments)
points = []
for i in range(1, segments):
points.append([start[0] + i * x_delta, start[1] + i * y_delta])
return [start] + points + [end]
print split([-10, 20], [20, 75], 5)
Output:
[[-10, 20], [-4.0, 31.0], [2.0, 42.0], [8.0, 53.0], [14.0, 64.0], [20, 75]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With