# Branch from the tree using GHPython and ranking them

I would like to select a branch from the tree using GHPython, can I do that?
a = [[1,2,3],[4,5],[6,7,8],[9,10]]
now if I say a[0], am getting 1,4,6 and 9. instead I want [1,2,3]. I really appreciate any help you can provide.
Vijesh

I have found the method. Keep the data as a data tree in the input of the component, and then start coding as x.Branch(0) will get [1,2,3]. Now the question is that how can I sort the branches from highest to lowest? Considering, I have only a single element in a branch. I really appreciate any help you can provide.

to sort the branches, convert them into list and bring them back to a tree i think.

``````import rhinoscriptsyntax as rs

def rankdata(a):
n = len(a)
ivec = sorted(range(n), key=a.__getitem__)
svec = [a[rank] for rank in ivec]
sumranks = 0
dupcount = 0
newarray = [0]*n
for i in range(n):
sumranks += i
dupcount += 1
if i == n-1 or svec[i] != svec[i+1]:
averank = sumranks / float(dupcount) + 1
for j in range(i-dupcount+1, i+1):
newarray[ivec[j]] = averank
sumranks = 0
dupcount = 0
return newarray

a = [5, 1, 3, 4]
ranks = rankdata(a)
print(ranks)
``````

thanks.