Yes you can use group curves then by joined curves as below.
You can find this node in archi-lab_grimshaw package.
and below the script from the node if you couldn’t find the package.
#Copyright(c) 2015, Konrad Sobon
# @arch_laboratory, http://archi-lab.net
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
inputCurves = IN
#join/group curves function
ignore_distance = 0.1 # Assume points this close or closer to each other are touching
Grouped_Lines = 
Queue = set()
Shape = 
Queue.add(Line_List.pop()) # Move a line from the Line_List to our queue
Current_Line = Queue.pop()
for Potential_Match in Line_List:
Points = (Potential_Match.StartPoint, Potential_Match.EndPoint)
for P1 in Points:
for P2 in (Current_Line.StartPoint, Current_Line.EndPoint):
distance = P1.DistanceTo(P2)
if distance <= ignore_distance:
Line_List = [item for item in Line_List if item not in Queue]
OUT = groupCurves(inputCurves)