PDA

View Full Version : sorting by position


dan12345
03-26-2008, 03:01 AM
Hello
i have a list of nodes, and i would like to sort them according to their
height
i know python has a list.sort(key = bla) function), but the question is:
how do i get the handle to node3d.getPosition()[1] so i can pass it
as the key ?
or is there another way?

thankz
dan

dan12345
03-26-2008, 03:06 AM
found the solution...

list.sort(lambda x, y: cmp(x.getPosition()[1], y.getPosition()[1])

does the job!

thankz anyway :)

farshizzo
03-26-2008, 11:32 AM
The best method is to use the key parameter instead of the cmp parameter. It is faster and more efficient. Here is some sample code:list.sort(key = lambda x: x.getPosition()[1])