def is_partition(G, communities):
 return all(((sum(((1 if (v in c) else 0) for c in communities)) == 1) for v in G))

def is_partition ( G , communities ) : return all ( ( ( sum ( ( ( 1 if ( v in c ) else 0 ) for c in communities ) ) == 1 ) for v in G ) )
return true if and only if communities is a partition of the nodes of g .