Cull boundary curves?


I’ve written a Python script that turns a network of connected lines into polygons.

The above image shows three geometries: the lighter, bigger polygon, the darker triangle, and the boundary polygon, represented by the pink outline.
This external hull is a problem that I encounter for some networks, but not all!
In my script I can’t get rid of this boundary right away - during the line sorting -, since it is ignorant towards checking for boundaries. It has no concept of all the possible polygons.
My hope is to sort them out afterwards.

Which would be an efficient way to filter out boundaries, starting from lines and indices of lines, forming polygons?
It’s possible that a whole bunch of polygons have to be checked. This is a rather simple example!
Furthermore, boundaries aren’t found for each line network. They mostly happen for cases like in the screenshot, where a smaller geometry (triangle) is included in a bigger polygon, and intersects the latter partially (with one side). (10.0 KB)