diff options
| author | Raf Guns <rafguns@gmail.com> | 2015-04-21 21:06:43 +0200 |
|---|---|---|
| committer | Raf Guns <rafguns@gmail.com> | 2015-04-28 21:26:53 +0200 |
| commit | af334856d64a6eb7b19217153d028eb59a113bc1 (patch) | |
| tree | 336595c2c7bea5c05b89baee5d1cbeddacef7716 /networkx/classes | |
| parent | 38b9ba5dfef7f5d702e450e82e493d6dc4dc67cb (diff) | |
| download | networkx-af334856d64a6eb7b19217153d028eb59a113bc1.tar.gz | |
Simplify and speed up nx.non_edges
Diffstat (limited to 'networkx/classes')
| -rw-r--r-- | networkx/classes/function.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/networkx/classes/function.py b/networkx/classes/function.py index bea850a2..698f8eda 100644 --- a/networkx/classes/function.py +++ b/networkx/classes/function.py @@ -498,12 +498,9 @@ def non_edges(graph): 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)) + for u, v in itertools.combinations(graph, 2): + if not graph.has_edge(u, v): + yield (u, v) @not_implemented_for('directed') |
