Skip to content

Instantly share code, notes, and snippets.

@anomit
Created September 2, 2009 12:16
Show Gist options
  • Save anomit/179680 to your computer and use it in GitHub Desktop.
Save anomit/179680 to your computer and use it in GitHub Desktop.
"""
Sorting nodes of a graph according to their degrees
Idea from: http://mail.python.org/pipermail/python-list/2002-July/152876.html
"""
#example adjacency list
adjlist = {'a':['b','c','d'],'b':['a','d'],'c':['a'],'d':['b','a']}
histogram = [ (len(value), key) for key, value in adjlist.iteritems() ]
histogram.sort()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment