3 Answers
3

The trick is in the brace sequence expansion expression {x..y} which, for integers x any y expands to the inclusive range of values (i.e. [x,y]) as a textual list. We need to throw in an eval too, since brace expansion happens before variable expansion.

A variation on the sequence expansion is a{x..y}b where "a" is prepended and "b" is appended to each term of the expansion: you can use this to append a "," and alter the datum variable fiddling if desired. Sequence expansion handles increments of 1, or -1 if x > y

You may also need to sort the output: iterating the keys of an associative array has no well-defined order, and you haven't stated if the input ranges are pre-sorted (so I didn't over-complicate the code).

Your Python code comes close, but e.g. cannot deal with the overlap of 4 and 5 for item B.

The following handles that correctly using a set() to prevent the overlap, setdefault to eliminate the explicit test it the key already exists in d_pos and .split() on the input line to be less dependent on the \t character and eliminating the explicit .strip():