def dijkstra(weightedGraph, start, end):
    """Implementation of Dijkstra algorithm:
    Use the dijkstra algorithm to find the shortest path through a directed
    graph (weightedGraph) from start to end.

    :param: weightedGraph: dict, dictionary within a dictionary pairing weights (distances) with
        node-pairings
    :param: start: int, starting point of path, should be 0
    :param: end: int, end point of path, should be (n, m) of Matrix M

    :return: path: array-like, array of indices of the shortest path, i.e. best-fitting saccade pairs
    :return: dist: float, sum of weights

    """
    dist = {}
    pred = {}
    to_assess = weightedGraph.keys()
    for node in weightedGraph:
        dist[node] = float('inf')
        pred[node] = None
    sp_set = []
    dist[start] = 0
    while len(sp_set) < len(to_assess):
        still_in = {node: dist[node] for node in [node for node in
            to_assess if node not in sp_set]}
        closest = min(still_in, key=dist.get)
        sp_set.append(closest)
        for node in weightedGraph[closest]:
            if dist[node] > dist[closest] + weightedGraph[closest][node]:
                dist[node] = dist[closest] + weightedGraph[closest][node]
                pred[node] = closest
    path = [end]
    while start not in path:
        path.append(pred[path[-1]])
    return path[::-1], dist[end]
