MCPcopy Create free account
hub / github.com/ActiveState/code / __setitem__

Method __setitem__

recipes/Python/578615_graph/recipe-578615.py:118–130  ·  view source on GitHub ↗

Set edge value. If tail does not exist, it is created and added to graph if necessary. >>> g = Graph(VertexType=WVertex) >>> g[1][2] = 1 >>> g[1][3] += 1 #new tail (3): starts as value False (0), now add 1. >>> print g {1: {2: 1, 3: 1}, 2: {}, 3:

(self, tail, value)

Source from the content-addressed store, hash-verified

116 return dict.get(self, tail, False)
117
118 def __setitem__(self, tail, value):
119 """Set edge value. If tail does not exist, it is created and added to graph
120 if necessary.
121
122 >>> g = Graph(VertexType=WVertex)
123 >>> g[1][2] = 1
124 >>> g[1][3] += 1 #new tail (3): starts as value False (0), now add 1.
125 >>> print g
126 {1: {2: 1, 3: 1}, 2: {}, 3: {}}
127 """
128 super(VertexCommon, self).__setitem__(tail, value)
129 if tail not in self._graph and tail!=self._id: #XXX ?do this first to preserve invariants in case vertex addition fails
130 self._graph.add(tail)
131
132 def copy(self): raise NotImplementedError
133

Callers

nothing calls this directly

Calls 2

__setitem__Method · 0.45
addMethod · 0.45

Tested by

no test coverage detected