insort

insort

Define a function insort(list, item, hi) which takes three arguments.

It should locate the proper insertion point for item in list to maintain sorted order and place item at that location. The parameter hi is the current index of item in list.

Implement a solution that does not have any list methods.

OPTIONAL

  • Implement a solution using list methods

Example

insort([1, 2, 3, -1], -1, 3) => [-1, 1, 2, 3]
insort([3, 5, 4], 4, 2) => [3, 4, 5]

Last updated