newbie question about dictionnary ?

johnagianis johnagianis at yahoo.com
Fri Sep 5 09:07:07 EDT 2003


"Sophie Alléon" <alleon at club-internet.fr> wrote in message news:<3f582f90$0$20952$7a628cd7 at news.club-internet.fr>...
> Hi,
> 
> CONTEXT
> I do numerical simulation for which I have to process mesh. A mesh is made
> of
> triangle which are made of points.
> I want from this information to create edges and build triangle from edges
> rather
> than from points.
> 
> PROBLEM
> An edge is shared by possibly more than one triangle.
> 
> ALGORITHM
> 
> have a triangle class  (made of 3 edges)
> have an edge   class   (made of 2 points and embeding a triangle list (those
> connected to the edge)
> 
> for each triangle construct its edges but I have to check if the edge
> already exists
> 
> for doing this I thought the dictionary was excellent but the key is a
> string while I want it
> to be the 2 points forming the edge ? How to do it ?
> 
> Have you a better idea ?
> 
> Thanks
> 
> Guillaume

Dictionary keys are not necessarily strings. It can be even class
instances!! You can have the following:

class edge:
    def __init__(self,x,y):
        self.a=x
        self.b=y
    def ...
    ....


pointA=(3,1)
pointB=(5,2)
edgeA=edge(pointA,pointB)

triangle={}

triangle[edgeA]=something

Well i think that a list would be ok. The use of a dictionary is for
making a relation (key->value).In this case i dont know what the value
could be.

John




More information about the Python-list mailing list