Returns an iterator over nodes contained in nbunch that are also in the graph. The nodes in nbunch are checked for membership in the graph and if not are silently ignored. Parameters ---------- nbunch : single node, container, or all nodes (default=
(self, nbunch=None)
| 561 | return 0 |
| 562 | |
| 563 | def nbunch_iter(self, nbunch=None): |
| 564 | """Returns an iterator over nodes contained in nbunch that are |
| 565 | also in the graph. |
| 566 | |
| 567 | The nodes in nbunch are checked for membership in the graph |
| 568 | and if not are silently ignored. |
| 569 | |
| 570 | Parameters |
| 571 | ---------- |
| 572 | nbunch : single node, container, or all nodes (default= all nodes) |
| 573 | The view will only report edges incident to these nodes. |
| 574 | |
| 575 | Returns |
| 576 | ------- |
| 577 | niter : iterator |
| 578 | An iterator over nodes in nbunch that are also in the graph. |
| 579 | If nbunch is None, iterate over all nodes in the graph. |
| 580 | |
| 581 | Raises |
| 582 | ------ |
| 583 | EasyGraphError |
| 584 | If nbunch is not a node or sequence of nodes. |
| 585 | If a node in nbunch is not hashable. |
| 586 | |
| 587 | See Also |
| 588 | -------- |
| 589 | Graph.__iter__ |
| 590 | |
| 591 | Notes |
| 592 | ----- |
| 593 | When nbunch is an iterator, the returned iterator yields values |
| 594 | directly from nbunch, becoming exhausted when nbunch is exhausted. |
| 595 | |
| 596 | To test whether nbunch is a single node, one can use |
| 597 | "if nbunch in self:", even after processing with this routine. |
| 598 | |
| 599 | If nbunch is not a node or a (possibly empty) sequence/iterator |
| 600 | or None, a :exc:`EasyGraphError` is raised. Also, if any object in |
| 601 | nbunch is not hashable, a :exc:`EasyGraphError` is raised. |
| 602 | """ |
| 603 | if nbunch is None: # include all nodes via iterator |
| 604 | bunch = iter(self._adj) |
| 605 | elif nbunch in self: # if nbunch is a single node |
| 606 | bunch = iter([nbunch]) |
| 607 | else: # if nbunch is a sequence of nodes |
| 608 | |
| 609 | def bunch_iter(nlist, adj): |
| 610 | try: |
| 611 | for n in nlist: |
| 612 | if n in adj: |
| 613 | yield n |
| 614 | except TypeError as err: |
| 615 | exc, message = err, err.args[0] |
| 616 | # capture error for non-sequence/iterator nbunch. |
| 617 | if "iter" in message: |
| 618 | exc = EasyGraphError( |
| 619 | "nbunch is not a node or a sequence of nodes." |
| 620 | ) |
no outgoing calls
no test coverage detected