Python Sort List Using Function With Sql How Do You Select