def insort(col, element, get=(lambda x: x)):
 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

def insort ( col , element , get = ( lambda x : x ) ) : 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
pythons bisect does not allow for a get/key so it can not be used on a list of dictionaries .