python implementation of dijkstra