En Mon, 02 Feb 2009 10:10:15 -0200, Alessandro Zivelonghi
<zasaconsult...@gmail.com> escribió:

*Ntop = odb.rootAssembly.instances['PART-1-1'].nodeSets['TOP'].nodes
*
Problem:
1) the list of nodes Ntop contains all the node labels [2673,   2675,
2676,   2677,   2678,   3655,   3656, 119939, 124154, 127919] already
ordered in ascending order.
What I need is the same list *ordered by coordinate_x* of each node, i.e.
from left to right in the model (unfortunately, for example node 124154
cames before node 3656 in the model, if you read the model from left to
right)

Use the key= argument to the sorted() builtin function
<http://docs.python.org/library/functions.html#sorted>

def get_node_x(node):
   return node.coordinates[0]

sorted_nodes = sorted(Ntop, key=get_node_x)

(For a list of reasonable size, that's fine. For a giant list, this could
be written more efficiently, although less readable)

1b) I don't understand which kind of data are EL, N, Ntop (list?) and how
can I sort Ntop  with the criterium based on coordinate_x (coordinate[0])

AFAIK those are plain lists. You can try:

py> print type(Ntop)

and see what happens. If you don't get <type 'list'>, try with:

py> type(Ntop).mro()

to see the chain of base classes.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to