I am trying to write a basic backtracking piece of code and have ran into an error with my list. I have created my list at the bottom just before calling the function, however I still get list assignment index out of range!
I have tried leaving the list empty by just saying arr = [] but nothing seems to work.
def printStrings(n, arr, i):
if n == i:
pass
arr[i] = 0
printStrings(n, arr, i+1)
arr[i] = 1
printStrings(n, arr, i+1)
if __name__ == "__main__":
n = 4
arr = [None] * n
printStrings(n, arr, 0)
I am expecting the list to be initialized when i write arr = [None] * n but i guess its not creating a list with 4 index's. Please help. Thanks