code: def select_neighbors_by_edge_attribute(docgraph, source,
                                         attribute=None, value=None, data=False):
      
      assert isinstance(docgraph, MultiGraph)
      for neighbor_id in docgraph.neighbors_iter(source):
          edges = docgraph[source][neighbor_id].values()
  
          if attribute is None:
              has_attrib = True # don't filter neighbors
          else:
              has_attrib = any(attribute in edge for edge in edges)
  
          if has_attrib:
              if value is None:
                  has_value = True
              elif isinstance(value, basestring):
                  has_value = any(edge.get(attribute) == value
                                  for edge in edges)
              else:  # ``value`` is a list/set/dict of values
                  has_value = any(edge.get(attribute) == v
                                  for edge in edges
                                  for v in value)
  
              if has_value:
                  if data:
                      yield (neighbor_id, docgraph.node[neighbor_id])
                  else:
                      yield neighbor_id
docs: Get all neighbors with the given edge attribute value(s).