I have a line of code from class that I don't understand fully and want some easier alternative to. What this does is , uses weightList, which is a list of edges that's connected to each other, and returns the edgelists with lowest corresponding value from the graph (adjacency matrix). This is for a Prim's Minimum Spanning Tree problem.
edge = sorted(weightList, key=lambda e:graph[e][e]);
Breaking it up a little bit could be enough. How about this?
get_edge_weight = lambda e: graph[e][e] sorted_weights = sorted(weightList, key=get_edge_weight) edge = sorted_weights