[Tutor] list comprehension question

Tom Musgrove tommusgrove__ at hotmail.com
Mon May 31 19:47:54 EDT 2004


I'm writing some code that takes two meshes, an original, and an altered 
mesh.  Finds the added and deleted edges/vertices.  And then modifiys a list 
of targets that were applied to the original mesh and modifies them to have 
the same behavior on the altered mesh.  (Ie the targets are mesh 
deformations for specified vertices, but the new mesh might have new 
vertices that need to be interpolated, or vertices that have been deleted, 
or moved, etc.)

I have two lists of keys that I have from creating edge dictionaries for the 
altered and original mesh, then using list comprehension to find the unique 
edges. giving, for instance, the following.

ListAUniqueEdges = {(1,5), (2,6), (3,7), (8,9)}
ListBUniqueEdges = {(2,7), (3,5), (1,6), (10,11)}

I need to create two dictionaries from the above, showing how the edges from 
lista relate to those in listb and vice versa, ie the resulting Dict would 

DictA = {(1,5): {(1,6), (3,5)}, (2,6): {(2,7), (1,6)}, (3,7): {(3,5), 
(2,7)}, (8,9):{}}

is there some elegant way to do this, I think it should be doable via list 
comprehension, but for some reason I can't think of the solution right now, 
and the power of google isn't helping...


Tom M.

Best Restaurant Giveaway Ever! Vote for your favorites for a chance to win 
$1 million! http://local.msn.com/special/giveaway.asp

More information about the Tutor mailing list