Skip to content

Commit bcacfb9

Browse files
committed
add __contains__ to edges.data() and edges.items() -
1 parent 1c1c37e commit bcacfb9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

edges.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ def __iter__(self):
3838
yield d
3939
def __repr__(self):
4040
return '{})'.format(list(self))
41+
def __contains__(self, key):
42+
# need to look at all data
43+
for k in self:
44+
if k == key:
45+
return True
46+
return False
4147

4248
class EdgeItems(UndirectedEdges):
4349
def __iter__(self):
4450
return self._items()
4551
def __repr__(self):
4652
return '{})'.format(list(self))
53+
def __contains__(self, key):
54+
(u,v),d = key
55+
return v in self._adj[u] and self._adj[u][v] == d
4756

4857

4958
class Edges(UndirectedEdges):

0 commit comments

Comments
 (0)