modularity function in python