Repository: networkx/networkx
Pull request: Updated networkx/classes/function.py . Solves Issue #5463
Fixes #5463

Problem statement:
Improve Examples Section of ```set_edge_attributes```
<!-- If you have a general question about NetworkX, please use the discussions tab to create a new discussion -->

<!--- Provide a general summary of the issue in the Title above -->


<!--- Tell us what happens instead of the expected behavior -->
While looking at the ```set_edge_attributes``` function, it doesn't include an example using multigraphs. As the ```values``` argument is passed different for non-multigraphs and multigraphs, I figured having a small example will show the difference easily. 

<!--- Tell us what should happen -->

<!--- Provide a minimal example that reproduces the bug -->

<!--- Please provide details about your local environment -->
NetworkX version: 2.6.2

<!--- Add any other context about the problem here, screenshots, etc. -->

Hints from issue discussion:
I agree that a multigraph example would be a nice improvement. The fact that `values` expects the dict keyed by 3-tuples is definitely worth highlighting.
Okay thanks! I will try to include an example and add a PR. Can you guide me on which file in the repo to be edited? 
> Can you guide me on which file in the repo to be edited?

Check out [our new contributor FAQ](https://networkx.org/documentation/latest/developer/new_contributor_faq.html#q-i-want-to-work-on-a-specific-function-how-do-i-find-it-in-the-source-code) which will hopefully give you some ideas for how to navigate the code base!

Commit message: Update networkx/classes/function.py

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>

Patch to review:
diff --git a/networkx/classes/function.py b/networkx/classes/function.py
index 6b9027fcfc9..eb3b1b0b081 100644
--- a/networkx/classes/function.py
+++ b/networkx/classes/function.py
@@ -793,6 +793,20 @@ def set_edge_attributes(G, values, name=None):
         >>> (1, 2) in G.edges()
         False
 
+    For multigraphs, the `values` dict is expected to be keyed by 3-tuples
+    including the edge key::
+
+        >>> G = nx.MultiGraph()
+        >>> edges = [(0,1), (0,1)]
+        >>> G.add_edges_from(edges)  # Returns list of edge keys
+        [0, 1]
+        >>> attributes = {(0,1,0): {"cost": 21}, (0,1,1): {"cost": 7}}
+        >>> nx.set_edge_attributes(G, attributes)
+        >>> G[0][1][0]["cost"]
+        21
+        >>> G[0][1][1]["cost"]
+        7
+
     """
     if name is not None:
         # `values` does not contain attribute names


Code review comments:
diff_hunk: @@ -793,6 +793,20 @@ def set_edge_attributes(G, values, name=None):
         >>> (1, 2) in G.edges()
         False
 
+    For multigraphs, the `values` dict is expected to be keyed by 3-tuples
+    including the edge key::
+
+        >>> G = nx.MultiGraph()
+        >>> edges = [(0,1), (0,1)]
+        >>> G.add_edges_from(edges)  # Returns list of edge keys
+        [0, 1]
+        >>> attributes = {(0,1,0): {"cost": 21}, (0,1,1): {"cost": 7}}
path: networkx/classes/function.py
text: @user1:
```suggestion
        >>> attributes = {(0, 1, 0): {"cost": 21}, (0, 1, 1): {"cost": 7}}
```

diff_hunk: @@ -793,6 +793,20 @@ def set_edge_attributes(G, values, name=None):
         >>> (1, 2) in G.edges()
         False
 
+    For multigraphs, the `values` dict is expected to be keyed by 3-tuples
+    including the edge key::
+
+        >>> G = nx.MultiGraph()
+        >>> edges = [(0,1), (0,1)]
path: networkx/classes/function.py
text: @user1:
```suggestion
        >>> edges = [(0, 1), (0, 1)]
```