code: def select_nodes_by_layer(docgraph, layer=None, data=False):
      
      for node_id, node_attribs in docgraph.nodes_iter(data=True):
          if layer is None:
              condition = True # don't filter nodes
          elif isinstance(layer, (str, unicode)):
              condition = layer in node_attribs['layers']
          else:  # ``layer`` is a list/set/dict of layers
              condition = any(l in node_attribs['layers'] for l in layer)
          if condition:
              if data:
                  yield (node_id, node_attribs)
              else:
                  yield node_id
docs: Get all nodes belonging to (any of) the given layer(s).
  
      Parameters
      ----------
      docgraph : DiscourseDocumentGraph
          document graph from which the nodes will be extracted
      layer : str or collection of str or None
          name(s) of the layer(s) to select nodes from. If None, returns all
          nodes
      data : bool
          If True, results will include node attributes.
  
      Yields
      ------
      nodes : generator of str or generator of (str, dict) tuple
          If data is False (default), a generator of node IDs that are present in
          the given layer. If data is True, a generator of (node ID, node attrib
          dict) tuples.