Python Forum
How can i list opposite attributes from maximal_matching - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: How can i list opposite attributes from maximal_matching (/thread-27085.html)



How can i list opposite attributes from maximal_matching - John_64 - May-25-2020

Hi everyone. I'm amateur on Python3 and Jupyter Notebook. For learning Python properly, I'm developing Python on the Jupyter Notebook. When i develop my project, i couldn't solve particular part which include listing opposite attributes according to maximal_matching(G) function.

First of all, i have an Erdös-Rengi graph with N nodes and probability of 0.5. I have specified number of N with random number generator 100 to 200. The value of N changes by 100 to 200.

Then, i successfully assigned variable to number of N nodes with in a for loop using a random number generator
that only generates 0 or 1. This means that in Erdös-Rengi graph, each node has value of 0 or 1.(randomly generated)

After that, i have specified 'pol' attribute to each node with using a user-defined node attribute. This means that;
If a node has variable of 0, 'pol' attribute will be done with '-'.
If a node has variable of 1, 'pol' attribute will be done with '+'.
My code:
def listToDict(lst):
    
    op = dict.fromkeys(lst , N)
    return op

pol_list=[]
for(N,value) in G.nodes(data=True):
    
    value['variable'] = random.randint(0, 1)       
    if value['variable'] == 0:
        pol = "-"
    elif value['variable'] == 1:
        pol = "+"
    
    pol_list.append(pol)
        
    
    nx.set_node_attributes(G,'pol',pol) 

node_list = list(G.nodes())

count_dict = { k:v for k,v in zip(node_list,pol_list)}

nx.set_node_attributes(G, count_dict, 'pol')
print(G.nodes('variable'))
print(" ")
print(G.nodes('pol'))
Then, i calculated maximal_matching of the Erdös-Rengi Graph(G). Now my problem is i want to take only opposite 'pol' values from the maximal_matching and i would like to print output like this:

NodeDataView({1: {'pol': '+'}, 3: {'pol': '-'}})
NodeDataView({5: {'pol': '-'}, 9: {'pol': '+'}})
NodeDataView({12: {'pol': '+'}, 32: {'pol': '-'}})
NodeDataView({25: {'pol': '-'}, 36: {'pol': '+'}})
…
I have searched lots of time in Internet but i can't get any informations.
For this problem,i tried this code but i think it was ridiculous.
def listToMaximalMatching(lst):
     
    op = dict.fromkeys(lst , N)
    return op

final_list = []
for(N,L1) in G.nodes(data=True):
    
    if(maximal_matching(G[0]) == '-' & maximal_matching(G[1]) == '+' ):
        list(G.nodes())
        
    elif(maximal_matching(G[0]) == '+' & maximal_matching(G[1]) == '-' ):
        list(G.nodes())
    else:
         break



RE: How can i list opposite attributes from maximal_matching - John_64 - May-31-2020

I solved my problem. Can you delete this post to avoid confusion?