topologiacal sort for dictionary