Add all the edges in ebunch_to_add. Parameters ---------- ebunch_to_add : container of edges Each edge given in the container will be added to the graph. The edges can be: - 2-tuples (u, v) or - 3-tuples (u, v, d) for
(self, ebunch_to_add, **attr)
| 204 | return key |
| 205 | |
| 206 | def add_edges_from(self, ebunch_to_add, **attr): |
| 207 | """Add all the edges in ebunch_to_add. |
| 208 | |
| 209 | Parameters |
| 210 | ---------- |
| 211 | ebunch_to_add : container of edges |
| 212 | Each edge given in the container will be added to the |
| 213 | graph. The edges can be: |
| 214 | |
| 215 | - 2-tuples (u, v) or |
| 216 | - 3-tuples (u, v, d) for an edge data dict d, or |
| 217 | - 3-tuples (u, v, k) for not iterable key k, or |
| 218 | - 4-tuples (u, v, k, d) for an edge with data and key k |
| 219 | |
| 220 | attr : keyword arguments, optional |
| 221 | Edge data (or labels or objects) can be assigned using |
| 222 | keyword arguments. |
| 223 | |
| 224 | Returns |
| 225 | ------- |
| 226 | A list of edge keys assigned to the edges in `ebunch`. |
| 227 | |
| 228 | See Also |
| 229 | -------- |
| 230 | add_edge : add a single edge |
| 231 | add_weighted_edges_from : convenient way to add weighted edges |
| 232 | |
| 233 | Notes |
| 234 | ----- |
| 235 | Adding the same edge twice has no effect but any edge data |
| 236 | will be updated when each duplicate edge is added. |
| 237 | |
| 238 | Edge attributes specified in an ebunch take precedence over |
| 239 | attributes specified via keyword arguments. |
| 240 | |
| 241 | Default keys are generated using the method ``new_edge_key()``. |
| 242 | This method can be overridden by subclassing the base class and |
| 243 | providing a custom ``new_edge_key()`` method. |
| 244 | |
| 245 | Examples |
| 246 | -------- |
| 247 | >>> G = eg.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc |
| 248 | >>> G.add_edges_from([(0, 1), (1, 2)]) # using a list of edge tuples |
| 249 | >>> e = zip(range(0, 3), range(1, 4)) |
| 250 | >>> G.add_edges_from(e) # Add the path graph 0-1-2-3 |
| 251 | |
| 252 | Associate data to edges |
| 253 | |
| 254 | >>> G.add_edges_from([(1, 2), (2, 3)], weight=3) |
| 255 | >>> G.add_edges_from([(3, 4), (1, 4)], label="WN2898") |
| 256 | """ |
| 257 | keylist = [] |
| 258 | for e in ebunch_to_add: |
| 259 | ne = len(e) |
| 260 | if ne == 4: |
| 261 | u, v, key, dd = e |
| 262 | elif ne == 3: |
| 263 | u, v, dd = e |