I have list of edges in 3D as following ((x1, y1, z1), (x2,y2,z2)) ..... ((x_k, y_k, z_k), (x_t, y_t, z_t))

From them, I need obtain list of vertex.

My current idea: Create initial emty set V

Check all edges, check coordinate of 2 points, if it is not in set V, add it to V.

I feel it is not fast when checking one by one whether 3D coordinate exist in set or not.

I need a cleaner and faster method? Any suggestion?

1 Answers

bubble On

Since all edges consist of vertices, you need just extract all vertices and drop duplicated ones, e.g.

>>> x = [((1,2), (1,5)), ((2,3), (4,5)), ((1, 2), (6,7))]
>>> set(sum(x, tuple()))
{(1, 2), (1, 5), (4, 5), (2, 3), (6, 7)}


>>> list(set(sum(x, tuple())))