Merge sorted lists in python

前端 未结 9 987
花落未央
花落未央 2020-12-19 00:50

I have a bunch of sorted lists of objects, and a comparison function

class Obj :
    def __init__(p) :
        self.points = p
def cmp(a, b) :
    return a.p         


        
9条回答
  •  一生所求
    2020-12-19 01:15

    I don't know whether it would be any quicker, but you could simplify it with:

    def GetObjKey(a):
        return a.points
    
    return sorted(a + b + c, key=GetObjKey)
    

    You could also, of course, use cmp rather than key if you prefer.

提交回复
热议问题