Skip to content

Instantly share code, notes, and snippets.

@scarecrow1123
Last active February 20, 2016 10:08
Show Gist options
  • Save scarecrow1123/7f437197a67131ae4985 to your computer and use it in GitHub Desktop.
Save scarecrow1123/7f437197a67131ae4985 to your computer and use it in GitHub Desktop.
Make a complete graph - Python one liner
def make_complete_graph(num_nodes):
"""takes number of nodes and returns a dict that represents
a complete graph(no self loops) with num_nodes"""
return {x: set([(lambda y: y)(y) for y in xrange(num_nodes) if y!= x]) for x in xrange(num_nodes)}
#remove the y!=x condition for self loops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment