I wrote a little program that inserts an element in a list. The program uses a binary search algorithm to find the spot where the new element should be allocated. I’m having trouble to change the original list content. What’s wrong in my code?
def Insert(TAB,V): for i in range(0, len(TAB)): j, count = binarySearch(TAB,V) TAB = TAB[:j] + [V] + TAB[j:] return "index =",j,"comparisons =", count
Source: Python Questions