Below is two sample list that i wish to sort individually.
For UB/WB case, I wish to sort by front digits and follow by digits after string ‘UB’/‘WB’
For RHS case, I wish to sort by digits before the first cross and follow by the second and third
enter image description here
Can anyone guide me on how I code using the sort() function in python?
You can extract the numbers, that you want to sort by, from the string, e.g. by splitting the string. Then use them as keys for sorting. After that build the string again.
import rhinoscriptsyntax as rs
from operator import itemgetter
dat = list()
for item in l:
n0, n1 = item.split("UB")
dat = sorted(dat, key=itemgetter(0,1))
a = ["%sUB%s" % (n0,n1) for n0, n1 in dat]
2023-09-07_name_sort_python.gh (7.8 KB)