def degree(self, nbunch=None, weight=None):
        # Test to see if nbunch is a single node, an iterator of nodes or
        # None(indicating all nodes). (nbunch in self) is True when nbunch
        # is a single node.
        if nbunch in self:
            nbrs = self.adj[nbunch]
            if weight is None:
                return sum([len(data) for data in nbrs.values()]) + (nbunch in nbrs and len(nbrs[nbunch]))
            deg = sum([d.get(weight, 1) for data in nbrs.values() for d in data.values()])
            if nbunch in nbrs:
                deg += sum([d.get(weight, 1) for key, d in nbrs[nbunch].items()])
            return deg
        if nbunch is None:
            nodes_nbrs = self.adj.items()
        else:
            nodes_nbrs = ((n, self.adj[n]) for n in self.nbunch_iter(nbunch))

        if weight is None:
            def d_iter():
                for n, nbrs in nodes_nbrs:
                    deg = sum([len(data) for data in nbrs.values()])
                    yield (n, deg + (n in nbrs and len(nbrs[n])))
        else:
            # edge weighted graph - degree is sum of nbr edge weights
            def d_iter():
                for n, nbrs in nodes_nbrs:
                    deg = sum([d.get(weight, 1)
                               for data in nbrs.values()
                               for d in data.values()])
                    if n in nbrs:
                        deg += sum([d.get(weight, 1)
                                    for key, d in nbrs[n].items()])
                    yield (n, deg)
        return d_iter()
Saves output references when a shard finishes.
dataset/ETHPy150Open networkx/networkx/networkx/classes/multigraph.py/MultiGraph.degree--crossover with--dataset/ETHPy150Open GoogleCloudPlatform/appengine-mapreduce/python/src/mapreduce/api/map_job/output_writer.py/OutputWriter.commit_output