Ideas on how to sort a list in a better way


#1

Hi everyone,

I am trying to sort my list in a way that gives me the desired outcome as you can see below:

Any ideas on how to achieve the desired outcome ?

Sorting List.dyn (91.3 KB)


#2

You want the outcome be the same order as the desired one?

If you can accomplish this by putting in the correct order by list create?


#3

hmmm so you want to sort your 4 lists based upon their first value?


#4

@hugo.paalman @3Pinter

I want to sort them in ascending order based on their first index value. so ideally start with 0 and finish with 300


#5

Hi
i hope this may be useful


#6

Something like this?


#7

This python should work:

# The inputs to this node will be stored as a list in the IN variables.
main = IN[0]

first = []
for vals in main:
    val = int(vals[0].split('-')[0])
    first.append(val)

sortlist = [x for _,x in sorted(zip(first,main))]

# Assign your output to the OUT variable.
OUT = sortlist

sortedpython


#8

@3Pinter @kennyb6

Thank you both. Both answers are really good :slight_smile: