Trim Model Line "Python Script"

im wondering is it possible to trim randomly selected lines with python code… i know its possible with scripts but with python…

maybe a work flow with a check loop

if (start point intersects model line )
end model line with start point


if (end point intersects model line)
start model line with end point

“”“hope i guess there is no 3rd itteration”""

is it possible to use this exprission in python code ???