Shortest path  routing algorithm in python