Skip to content

Instantly share code, notes, and snippets.

View hagberg's full-sized avatar

Aric Hagberg hagberg

View GitHub Profile
@hagberg
hagberg / gist:3751844
Created September 19, 2012 19:53
networkx depth first traversal in sorted order
"""
DFS with children visited in sorted order.
Nodes must be sortable.
Basic algorithms for depth-first searching.
Based on http://www.ics.uci.edu/~eppstein/PADS/DFS.py
by D. Eppstein, July 2004.
"""
__author__ = """\n""".join(['Aric Hagberg <hagberg@lanl.gov>'])
import networkx as nx
import sys
G=nx.read_gexf(sys.argv[1])
for u,d in G.nodes(data=True):
print(u,d)
for u,v,d in G.edges(data=True):
print(u,v,d)
print(G.graph)
print "G",type(G)
nx.write_gexf(G,'test.gexf')