You can simply use `return min(G, key=G.degree)`.