Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list of 60 sublists. Each sublist has 30 sub-sub lists. Each sub-sub-list looks like [x, y] For each sub-sub lists, how can I find the closest sub-sub list of the next sub-list?

For example, I am in sub-list[0], sub-sub-list[0]. Now I go to sub-list[1] and search for the sub-sub-list that has the closest x,y coordinates.

This is an example of what I am trying to accomplish:
input = [ [[99, 87], [400, 500], [300, 95]],
[[297, 107], [100, 118], [405, 450]] ]

output = [ [[99, 87],[100, 118]], [[400, 500], [405, 450]], [[300, 95], [297, 107]] ]


What I have tried:

I have tried something like this, maybe calculate the smallest distance between the x and y coordinates between a subsublist and another subsublist of another sublist..
Python
for i in range(1,len(listt)):
    for sublist[i] in listt:
        for j in range(len(sublist[i]))
            for subsublist[j] in sublist[i]:
Posted
Updated 11-Apr-19 16:40pm
v4
Comments
Patrice T 11-Apr-19 10:57am    
Show a sample of your data.
List 1
SubList 11
SubSubList 111
SubSubList 112
SubList 12
...
iliketocode 11-Apr-19 11:19am    
This is an example of what I am trying to accomplish:
input = [ [[99, 87], [400, 500], [300, 95]],
[[297, 107], [100, 118], [405, 450]] ]

output = [ [[99, 87],[100, 118]], [[400, 500], [405, 450]], [[300, 95], [297, 107]] ]
Patrice T 11-Apr-19 11:37am    
Use Improve question to update your question.
So that everyone can pay attention to this information.

You're dealing with "points"; so you can calculate the distance between any 2 points and find the one that is closest.

c# - Calculating the distance between 2 points - Stack Overflow[^]
 
Share this answer
 
Quote:
How to find the most similar sub list of another list?

First, you need to understand the problem, and reformulating in a clear way is a good start.
Quote:
Each sub-sub-list looks like [x, y]

Each sub-sub-list is x and y coordinates of what is commonly named a point.
The concept of point makes it easier to understand the problem.
Quote:
how can I find the closest sub-sub list of the next sub-list?

Is reformulated as: for a given point, how to find closest point in a list of points?
This is the heart of your problem.
In your problem, lists are just a repeat of same problem.

Unless you give more details, brute force is probably the best approach.

To get help on your code, show it and explain where you are stuck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900