problem with list: how to count different elements?
Hello experts!
Im working with graphs.
My code is:
import numpy as np
import networkx as nx
M = np.zeros([6,6])
M[0,2]=1
M[2,0]=1
M[2,3]=1
M[3,2]=1
M[2,1]=1
M[1,2]=1
M[4,5]=1
M[5,4]=1
G=nx.Graph(M)
A=nx.node_connected_component(G,2)
Doing that, A
is a list with all the nodes connected with the node 2
, ie: A=[0, 1, 2, 3, 2]
1) Why the element '2' is repeated?
2) If, instead, we use A=nx.node_connected_component(G,0)
, we get A=[0, 1, 2, 3]
. In this case: why now the element '0' is not repeated?
3) If we have a list K=[1,2,3,4,1,1,1]
, and we do P=list(set(K))
, we get P=[1,2,3,4]
(doing that we can eliminate the repeated elements in the list). But if I do the same with the list A
obtained in my code, I get A=[0, 1, 2, 3, 2]
. Why this doest work?
Please help!
Thanks a lot