def polyline2linesegments(polyline):
    """Convert a polyline to a sequence of lines"""
    if len(polyline) < 2:
        raise ValueError("A polyline must have at least length 2")
    result = []
    for p0, p1 in zip(polyline, polyline[1:]):
        result.append((p0, p1))
    return result