Python: IndexError: list index out of range – trying to count two numbers from list in a for loop

Advertisements I´m trying to write a code in python, that should make an arithmetic average from a numbers in list – The user inputs numbers that are converted into the list as integers, then I use for loop to count the amount of numbers in list, this I save to variable, after that I want… Read More Python: IndexError: list index out of range – trying to count two numbers from list in a for loop

Why am I getting IndexError: list index out of range error even though I have a proper list

Advertisements with open(‘Input’,’r’) as f: while len(a)>0: a=f.readline() #I am going to search for a command to execute in the txt file w_in_line=a.split(‘,’) #words in line command_word_box=w_in_line[0].split()#I took the command word out of the line command_word=str(command_word_box[0]) pat_name=w_in_line[0].replace(command_word,”) w_in_line[0]=pat_name for word in command_word_box: #searching for commands if word==’create’: create (w_in_line) else: continue The text file is:… Read More Why am I getting IndexError: list index out of range error even though I have a proper list

length of list read from a csv varies, depending on when a read is performed

Advertisements I’m trying to write a simple function that reads in a csv and stores its content inside a list and either returns said list formatted or a string containing the information on why the csv is empty. For clarification, the csv is provided by an API called via curl. If there is new data… Read More length of list read from a csv varies, depending on when a read is performed

Index error in binary search in an infinite sorted array

Advertisements The program gives IndexError: list index out of range in binary search in the infinite sorted array when the element does not exist or is too large def binarySearch(l,ele,low=0,high=None): if(high==None): high=len(l)-1 if(low>high): return -1 mid= int((low+high)/2) pEle = l[mid] if(pEle==ele): return mid elif(pEle>ele): return binarySearch(l,ele,low,mid-1) else: return binarySearch(l,ele,mid+1,high) # This is a function that… Read More Index error in binary search in an infinite sorted array