The following script returns **tuple of sorted nodes**(“text”, bounding box dimensions) i.e

Tuple[Tuple[graphanno.Node,…],…],

where

Tuple[graphanno.Node,…]

represents a line.

But, i want to return the tuple of **indices of sorted nodes** i.e

Tuple[Tuple[int,…],…],

Following is the script that sorts nodes from left to right and returns tuple of sorted nodes.

```
def sort_nodes_into_lines(
nodes: Iterable[graphanno.Node],
) -> Tuple[Tuple[graphanno.Node, ...], ...]:
"""
Merge nodes that belong to one line.
The algorithm does the following:
1. Sort nodes by x-coordinate.
2. Iterate through them and merge those that are close in x- and have
overlap in y-direction to lines.
3. If the current node does not belong to a previously seen line,
start a new line from the node.
Parameters
----------
nodes
The nodes that shall be sorted.
Returns
-------
Tuple[Tuple[graphanno.Node,...],...]
A tuple of the nodes sorted.
"""
nodes_sorted = sorted(nodes, key=lambda node: node.box.origin_x)
reference, *remainder = nodes_sorted
lines: Dict[graphanno.Node, List[graphanno.Node]] = {reference: [reference]}
for node_idx, node in enumerate(remainder, start=1):
is_matched = False
for reference, line in lines.items():
if _has_sufficient_y_overlap(reference, node):
*_, last_in_row = line
if _in_x_proximity(last_in_row, node):
line.append(node)
is_matched = True
break
if not is_matched:
lines[node] = [node]
return tuple(
sorted(
(tuple(line) for line in lines.values()),
key=_get_line_origin_x,
)
)
def _get_line_origin_x(nodes: Sequence[graphanno.Node]) -> int:
"""Find min value of y coordinate of the origin of the bounding box."""
return min(node.box.origin_y for node in nodes)
```

Any help would be appreciated!

Thank you!