python version of code for reshaping and sorting mallet output