code: def findCommunities(G):
  	
  	
  	infomapWrapper = infomap.Infomap("--two-level")
  
  	print("Building Infomap network from a NetworkX graph...")
  	for e in G.edges():
  		infomapWrapper.addLink(*e)
  
  	print("Find communities with Infomap...")
  	infomapWrapper.run();
  
  	tree = infomapWrapper.tree
  
  	print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))
  
  	communities = {}
  	for node in tree.leafIter():
  		communities[node.originalLeafIndex] = node.moduleIndex()
  
  	nx.set_node_attributes(G, name='community', values=communities)
  	return tree.numTopModules()
docs: Partition network with the Infomap algorithm.
  	Annotates nodes with 'community' id and return number of communities found.