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
TAB.insert(j,V)TABand have something that looks likeTAB = Insert(TAB, V), or do not change the returned value but replaceTAB = ...withTAB[:] = ...to change the content of the list in place.