I'm creating a class where one of the methods inserts a new item into the sorted list. The item is inserted in the corrected (sorted) position in the sorted list. I'm not allowed to use any built-in list functions or methods other than []
, [:]
, +
, and len
though. This is the part that's really confusing to me.
What would be the best way in going about this?
Use the insort function of the bisect module:
Hint 1: You might want to study the Python code in the bisect module.
Hint 2: Slicing can be used for list insertion:
This is the best way to append the list and insert values to sorted list:
You should use the bisect module. Also, the list needs to be sorted before using bisect.insort_left
It's a pretty big difference.
This is a possible solution for you: