How To Write A Sort Function In Python