I have to find the sub-lists in a nested list, in order to get a result list r
, using Python.
- Result list
r
is build from and initial listl
. - 1st sub-list in
r
must contain starting pointstart
, and intermediate sub-lists that are connected by elements from listp
. - The last sub-list in
r
must contain ending pointend
.
It is like finding the proper sub-lists to traverse a nested list.
Here a small example.
#starting pointstart = 1#ending pointend = 9 #items to be used to link "start" and "end" points.p = [2, 4, 5]#complete nested listl = [ [0, 7], [1, 2], [8, 15, 19, 20], [0, 6], [2, 3, 5], [10, 14], [5, 8, 3, 4], [4, 9, 6], [14, 21], [20, 9]]#result list, with "start" in sublist 0, "end" in sublist 3.r = [ [1, 2],#----^ [2, 3, 5], [5, 8, 3, 4], [4, 9, 6]#-------^]
thanks in advance for your help,
Best regards.