py code for generating partition statistics