python类cmp()的实例源码

python2_3.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def cmpToKey(mycmp):
    'Convert a cmp= function into a key= function'
    class K(object):
        def __init__(self, obj, *args):
            self.obj = obj
        def __lt__(self, other):
            return mycmp(self.obj, other.obj) < 0
        def __gt__(self, other):
            return mycmp(self.obj, other.obj) > 0
        def __eq__(self, other):
            return mycmp(self.obj, other.obj) == 0
        def __le__(self, other):
            return mycmp(self.obj, other.obj) <= 0
        def __ge__(self, other):
            return mycmp(self.obj, other.obj) >= 0
        def __ne__(self, other):
            return mycmp(self.obj, other.obj) != 0
    return K
python2_3.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def cmpToKey(mycmp):
    'Convert a cmp= function into a key= function'
    class K(object):
        def __init__(self, obj, *args):
            self.obj = obj
        def __lt__(self, other):
            return mycmp(self.obj, other.obj) < 0
        def __gt__(self, other):
            return mycmp(self.obj, other.obj) > 0
        def __eq__(self, other):
            return mycmp(self.obj, other.obj) == 0
        def __le__(self, other):
            return mycmp(self.obj, other.obj) <= 0
        def __ge__(self, other):
            return mycmp(self.obj, other.obj) >= 0
        def __ne__(self, other):
            return mycmp(self.obj, other.obj) != 0
    return K
__init__.py 文件源码 项目:imagepyqt 作者: Image-Py 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def cmpToKey(mycmp):
    'Convert a cmp= function into a key= function'
    class K(object):
        def __init__(self, obj, *args):
            self.obj = obj
        def __lt__(self, other):
            return mycmp(self.obj, other.obj) < 0
        def __gt__(self, other):
            return mycmp(self.obj, other.obj) > 0
        def __eq__(self, other):
            return mycmp(self.obj, other.obj) == 0
        def __le__(self, other):
            return mycmp(self.obj, other.obj) <= 0
        def __ge__(self, other):
            return mycmp(self.obj, other.obj) >= 0
        def __ne__(self, other):
            return mycmp(self.obj, other.obj) != 0
    return K

## python2_3
python2_3.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def cmp(a,b):
        if a>b:
            return 1
        elif b > a:
            return -1
        else:
            return 0
python2_3.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def cmp(a,b):
        if a>b:
            return 1
        elif b > a:
            return -1
        else:
            return 0
misc.py 文件源码 项目:hakkuframework 作者: 4shadoww 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
arrays.py 文件源码 项目:fandango 作者: tango-controls 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def decimate_custom(seq,cmp=None,pops=None,keeptime=3600*1.1):
    """ 
    @NOTE: Although faster, filter_array does a better decimation for trends
    It will remove all values from a list that doesn't provide information.
    In a set of X consecutive identical values it will remove all except 
    the first and the last.
    A custom compare method can be passed as argument
    :param seq: a list of (timestamp,value) values
    """
    if len(seq)<3: return seq
    if len(seq[0])<2: return seq
    import __builtin__
    cmp = cmp or __builtin__.cmp
    pops = pops if pops is not None else []
    while pops: pops.pop() 
    x0,x1,x2 = seq[0],seq[1],seq[2]

    for i in range(len(seq)-2):

        if not cmp(x0[1],seq[i+1][1]) and not cmp(seq[i+1][1],seq[i+2][1]):
            pops.append(i+1)
        else: 
            x0 = seq[i+1]

    for i in reversed(pops):
        seq.pop(i)
    return seq
__init__.py 文件源码 项目:imagepyqt 作者: Image-Py 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def cmp(a,b):
        if a>b:
            return 1
        elif b > a:
            return -1
        else:
            return 0
misc.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:islam-buddy 作者: hamir 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:UMOG 作者: hsab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:beepboop 作者: nicolehe 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:hackathon 作者: vertica 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)
misc.py 文件源码 项目:yatta_reader 作者: sound88 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def cmp(x, y):
        """
        cmp(x, y) -> integer

        Return negative if x<y, zero if x==y, positive if x>y.
        """
        return (x > y) - (x < y)


问题


面经


文章

微信
公众号

扫码关注公众号