improving a huge double-for cycle

Tino Wildenhain tino at
Thu Sep 18 17:44:21 CEST 2008


Alexzive wrote:
> Hello there :) ,
> I am a python newbie and need to run following code for a task in an
> external simulation programm called "Abaqus" which makes use of python
> to access the mesh (ensamble of nodes with xy coordinates) of a
> certain geometrical model.
> [IN is the starting input containing the nodes to be check, there are
> some double nodes with the same x and y coordinates which need to be
> removed. SN is the output containing such double nodes]
> Code: Select all
>     for i in range(len(IN)): #scan all elements of the list IN
>       for j in range(len(IN)):
>         if i <> j:
>          if IN[i].coordinates[0] == IN[j].coordinates[0]:
>            if IN[i].coordinates[1] == IN[j].coordinates[1]:
>               SN.append(IN[i].label)

for item in IN: # (what a name! ;)
     # provided coordinates is a tuple

dupes=[items for items in data.values() if len(items)>1]

should give you a resulting list of lists of elements in IN
which occur more then once per coordinates.
You can then decide which ones to remove or whatever.

If you want to have the output only containing nodes to remove,
the following would work:

for items in data.values():


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <>

More information about the Python-list mailing list