Python script implementing Dijkstra