0

I have a list of lists l that looks something like l = [[1,2],[3,2]] and I need to keep adding more lists to l. l is sorted by the first element of each sublist and I was trying to add more elements to l using the bisect.insort_left() function.

On python's documentation https://docs.python.org/3/library/bisect.html#bisect.insort_left it says you can pass key to insort_left() similar to the sort() function in python. But I tried this bisect.insort_left(l, [5,6], key=lambda x: x[0]) and python gave me this error "TypeError: 'key' is an invalid keyword argument for bisect_right()". Does anyone know how to fix this? Thank you!

p.s. bisect already sorts my list l by the first element of each sublist by default, but I still wanna know how to use a key function just in case next time I run into a similar problem.

Nathan
  • 205
  • 1
  • 2
  • 7

0 Answers0