Prioritization function needed (recursive help!)

Kent Johnson kent at kentsjohnson.com
Mon Jan 21 17:50:18 EST 2008


rh0dium wrote:
> Hi all,
> 
> I need some help on writing a recursive priority function
> 
> Given a list = [ A, B, C, D]
> 
> Where the following constraints are in place:
> 
> A depends on [B, C]
> C depends on [B]
> 
> Figure out real order that prioritizes these.

You need a topological sort.
http://en.wikipedia.org/wiki/Topological_sort

Two Python implementations:
http://pypi.python.org/pypi/topsort/0.9
http://www.bitformation.com/art/python_toposort.html

Kent



More information about the Python-list mailing list