How To Write Sort Function In Python