New to Python and Python mail List

lavanya addepalli phani.lav at gmail.com
Thu Jul 17 11:39:40 EDT 2014


Hello Everyone

I am very much new to python scripting and i am here for knowledge
exchange.

I am trying to read a file with node pairs and weight.
I have to find the neighbours of each pair individual and combined
both also count them.
Later find the ratio of the neighbours that each node has. I am stuck
with finding nodes.

infile.txt

0_node1 0_node2 0w
1_node1 1_node2 1w
2_node1 2_node2 2w
3_node1 3_node2 3w
4_node1 4_node2 4w


import networkx as nx
import matplotlib.pyplot as plt

G=nx.Graph()
G = nx.read_edgelist('infile.txt', data=[("weight", float)])

def get_triangle(G):
  for n1 in G.nodes:
    neighbors1 = set(G[n1])
    for n2 in filter(lambda x: x>n1, nodes):
	neighbors2 = set(G[n2])
	common = neighbors1 & neighbors2
	for n3 in filter(lambda x: x>n2, common):
	  print n1
	  print n2
	  print n3

Any suggestion will be appreciated. Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140717/856c36c2/attachment.html>


More information about the Python-list mailing list