Skip to content

Instantly share code, notes, and snippets.

@versae
Created October 21, 2012 00:18
Show Gist options
  • Save versae/3925318 to your computer and use it in GitHub Desktop.
Save versae/3925318 to your computer and use it in GitHub Desktop.
Neighbors function : problematic
def find_neighbors(n, v, visited=set()):
"""
Finds a node's neighbors to n degrees of seperation.
Param n: degrees of seperation. n > 1
v: node id
Return: a list of neighbors to the nth degree with no duplicates or 'NoneType'
"""
neighbors = set(v.neighbors)
visited.update([v])
if n > 1:
for neighbor in neighbors - visited:
n_neighbors = find_neighbors(n - 1, neighbor, visited)
neighbors.update(n_neighbors)
return neighbors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment