Вы можете просто подсчитать ребра в подграфе, вызванные узлами в сообществе:
import networkx as nx
g = nx.Graph()
g.add_edges_from([(1,3), (2,3), (2,4), (3,4), (3,8), (5,7), (6,7)])
communities = [[1,2,3,4,8], [5,6,7]]
for clist in communities:
community_graph = g.subgraph(clist)
print(community_graph.number_of_edges(), list(community_graph.edges()))
дает вывод:
5 [(1, 3), (3, 2), (3, 4), (3, 8), (2, 4)]
2 [(5, 7), (6, 7)]