Hello, I would like to divide lists taking into account the first item as shown in the image, any ideas
Hi @Piscis
Perhaps a List.FirstItem set to (@)@L2 and a List.GroupByKey using those First Items as keys?
3 Likes
Here is an option in python ( Also handles if the lists are shuffled )
from itertools import groupby
list_of_lists = IN[0]
# Sort the list of lists based on the first and then second element
sorted_lists = sorted(list_of_lists, key=lambda x: (x[0], x[1]))
# Group the sorted lists by the first element
grouped_lists = [list(group) for _, group in groupby(sorted_lists, key=lambda x: x[0])]
OUT = grouped_lists
3 Likes