adapt to python3
simplify key function of sorted