Simplifying List


Can someone help me create a new list from this data structure that removes index 1. I would like to have lists with elements rather than multiple lists within lists.

Thank You

Hi @shahahmad
Can you post the code content of the node?
Looks to be a simple fix revising outputs.

I do not want to modify this list because I need the distances. I would like to create a new one using this node.

Likely an easy solution with a Zip function, or removing one. Can’t say without seeing the code.

For a node based solution: List.DropItems (to drop the first item), then List.FirstItem (to pull all the elements out of the sublists).

Certainly a more functional method in the hidden code though.

Yep, @jacob.small a visual below.

If you provide the python node code then the outputs can be adjusted to output a list of elements and a list of distances directly from the node.

Thanks for the assistance. Here is the code.

Whoops deleted instead of editing :sweat_smile:

for dimond in dimonds:
    dimond_result = [dimond]
    # Add in two more lists at line 14
    dimond_elements = []
    dimond_distances = []
    
    
        # Then add the closest elements to lists at line 38
        closest_elements = temp_elements[:16]
        for closest in closest_elements:
            dimond_elements.append(closest[0])
            dimond_distances.append(closest[1])
    
    # Then add the new lists to the result for the current dimond, this replaces both lines 39 and 40
    dimond_result.append(dimond_elements)
    dimond_result.append(dimond_distances)
1 Like

Thanks a lot homie. Much appreciated.

Ewan,

One last question regarding this code here. I was able to remove the distances from the list. Is there any way I can reorder the new list of elements based on a parameter value? Please see image below.

Thank You

Via nodes: List.SortByKey node. :slight_smile:

SortByKey gives me an error :frowning:
List.SortByKey operation failed. One or more input types are not matching. Lists as keys are not supported.

Hi @shahahmad try @ Lv2

2 Likes

Thank You Sir!