Partition Function In String In Python