diff options
| author | Kemal Maulana <kemskems12@gmail.com> | 2014-04-28 17:15:49 +0900 |
|---|---|---|
| committer | Kemal Maulana <kemskems12@gmail.com> | 2014-04-28 17:15:49 +0900 |
| commit | 31868a4fc81f3decf46dfaecc514b81ee517fbf6 (patch) | |
| tree | 998067f35e07e6757d9ef783eb87aaade611a1bb /networkx/classes/function.py | |
| parent | 0b19c537ca74cef26b02359cb406726cbae05eab (diff) | |
| download | networkx-31868a4fc81f3decf46dfaecc514b81ee517fbf6.tar.gz | |
Revised code
Diffstat (limited to 'networkx/classes/function.py')
| -rw-r--r-- | networkx/classes/function.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/networkx/classes/function.py b/networkx/classes/function.py index f08fec1e..9f035b98 100644 --- a/networkx/classes/function.py +++ b/networkx/classes/function.py @@ -439,11 +439,14 @@ def non_edges(graph): non_edges : iterator Iterator of edges that are not in the graph. """ - S = set() - for u in graph.nodes_iter(): - for v in non_neighbors(graph, u): - if (u, v) not in S: - S.add((u, v)) - if not graph.is_directed(): - S.add((v, u)) + if graph.is_directed(): + for u in graph.nodes_iter(): + for v in non_neighbors(graph, u): yield (u, v) + else: + S = set() + for u in graph.nodes_iter(): + for v in non_neighbors(graph, u): + if (u, v) not in S: + yield (u, v) + S.add((v, u)) |
