Python parsing code to clean input for processing