for example if we have l=[[0,1,2],[3,4,5,6],[4,5,6]]
since the list [3,10,11]
is of bigger size we can sort and return result as l=[[0,1,2], [4,5,6], [3,4,5,6]]
now if we append [1] to list it gives==> [[1],[0,1,2],[4,5,6],[3,4,5,6]]
basically i am saying that like in bisect.insort(list,element)
it automatically inserts the element at its correct position by using sorting methods but here i like to insert the element in terms of length.
if i explain more clearly then if you are a c++ user then
struct cmp {
bool operator() (const pair<int, int> &a,
const pair<int, int> &b) const {
int lena = a.second - a.first + 1;
int lenb = b.second - b.first + 1;
if (lena == lenb) return a.first < b.first;
return lena > lenb;
}
};
set<pair<int, int>, cmp> segs;
I want this type of thing in python