def subgraph(graph, id, distance=<NUM_LIT:1>):
g = graph.copy(empty=True)<EOL>if isinstance(id, (FunctionType, LambdaType)):<EOL><INDENT>id = [node.id for node in filter(id, graph.nodes)]<EOL><DEDENT>if not isinstance(id, (list, tuple)):<EOL><INDENT>id = [id]<EOL><DEDENT>for id in id:<EOL><INDENT>for n in flatten(graph[id], distance):<EOL><INDENT>g.add_node(n.id, n.r, n.style, n.category, n.label, (n==graph.root), n.__dict__)<EOL><DEDENT><DEDENT>for e in graph.edges:<EOL><INDENT>if g.has_key(e.node1.id) andg.has_key(e.node2.id):<EOL><INDENT>g.add_edge(e.node1.id, e.node2.id, e.weight, e.length, e.label, e.__dict__)<EOL><DEDENT><DEDENT>return g<EOL>
Creates the subgraph of the flattened node with given id (or list of id's).
    Finds all the edges between the nodes that make up the subgraph.