I have a line dataset that contains some lines where the "end points" are actually found in the middle of the line. In the image below, the nodes are shown in green and one of the end points in red. The line doubles back on itself.
How would I ensure the end points are actually at the end of the line, and remove the overlap?

These lines are both valid, and complex - as they have overlaps, as confirmed using Shapely.
>>> from shapely.wkt import loads
>>> wkt = "LINESTRING (0 0, 2 0, 1 0)"
>>> l = loads(wkt)
>>> l.is_valid
True
>>> l.is_simple
False
Ordering the coordinates would work in some cases:
>>> sorted(l.coords)
[(0.0, 0.0), (1.0, 0.0), (2.0, 0.0)]
But not in others as it would change the geometry of the line:
>>> wkt = "LINESTRING (0 0, 2 0, 1 -1)"
>>> l = loads(wkt)
>>> sorted(l.coords)
[(0.0, 0.0), (1.0, -1.0), (2.0, 0.0)]
Attempts at buffering the line with a 0 buffer, and merging lines have not changed the coordinate order.