WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   sorting by position (https://forum.worldviz.com/showthread.php?t=1422)

dan12345 03-26-2008 03:01 AM

sorting by position
 
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

got it
 
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:
Code:

list.sort(key = lambda x: x.getPosition()[1])


All times are GMT -7. The time now is 12:40 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC