

def insort(col, element, get=(lambda x: x)):
    "Python's bisect does not allow for a get/key\n    so it can not be used on a list of dictionaries.\n    Inserts element into the sorted collection col via\n    a binary search.\n    if element is not directly compairable the kwarg get may\n    be a callable that transforms element into a compairable object.\n    ie: A lambda that returns a certain key of a dict or attribute of an object\n    :param list col: The collection to insort into\n    :param ? element: The Element to be insortted into col\n    :param callable get: A callable that take a type of element and returns a compairable\n    "
    if (not col):
        col.insert(0, element)
        return col
    (lo, hi) = (0, len(col))
    while (lo < hi):
        mid = int(((hi + lo) / 2))
        if (get(col[mid]) > get(element)):
            hi = mid
        else:
            lo = (mid + 1)
    col.insert(lo, element)
    return col

dataset/ETHPy150Open CenterForOpenScience/osf.io/website/files/utils.py insort/original