"""
Ego graph.

"""
#    Copyright (C) 2010 by 
#    Aric Hagberg <hagberg@lanl.gov>
#    Dan Schult <dschult@colgate.edu>
#    Pieter Swart <swart@lanl.gov>
#    All rights reserved.
#    BSD license.
__author__ = """\n""".join(['Drew Conway <drew.conway@nyu.edu>',
                            'Aric Hagberg <hagberg@lanl.gov>'])
__all__ = ['ego_graph']

def ego_graph(G,n,center=True):
    """Returns induced subgraph of neighbors centered at node n. 
    
    Parameters
    ----------
    G : graph
      A NetworkX Graph or DiGraph

    n : node 
      A single node 

    center : bool, optional
      If False, do not include center node in graph 

    """
    nodes=set([n])  # add center node
    nodes.update(G.neighbors(n)) # extend with neighbors
    H=G.subgraph(nodes)
    if not center:
        H.remove_node(n)
    return  H

@@ -349,16 +349,39 @@
 raph'%5D%0A%0A
+import networkx as nx%0A%0A
 def ego_
@@ -390,16 +390,25 @@
 aph(G,n,
+radius=1,
 center=T
@@ -599,16 +599,99 @@
  node %0A%0A
+    radius : integer%0A      Include all neighbors of distance%3C=radius from n%0A      %0A
     cent
@@ -780,98 +780,67 @@
     
-nodes=set(%5Bn%5D)  # add center node%0A    nodes.update(G.neighbors(n)) # extend with neighbors
+sp=nx.single_source_shortest_path_length(G,n,cutoff=radius)
 %0A   
@@ -857,13 +857,17 @@
 aph(
-nodes
+sp.keys()
 )%0A  

Add option to build ego graph with specified radius