sort levels in python script