dependency algorithm

Robert Kern robert.kern at gmail.com
Wed Nov 14 17:53:08 EST 2007


Tom Jones wrote:
> Hi,
> 
> Consider tuples of the above numbers in the form:
>    (a,b)
> 
> Suppose this relation means:
>    a depends on b
> 
> Given a list of tuples, I would like an algorithm to return the proper 
> ordering of the elements...and if the ordering has a loop (which in this 
> case, prevents a proper ordering), then it should return None.

Google for "topological sort python". There are several implementations out there.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list