I've been trying to work on a function for an assignment and I'm new to coding. Part of it is to make user insert item to list by entering the desired item and the index without the built-in functions. Currently, I've got the code to replace the item in that index but I can't get it to do what it's supposed to.
Object is the item, and the list is in the main function.
def add(list, obj, index):
nlist = []
print("Your list ", list)
item = input("Insert item: ")
index = int(input("Index: "))
i = 0
for e in list:
if i < index:
nlist.append(e)
i += 1
elif i == index:
nlist.append(obj)
i += 1
elif i > index:
nlist.append(e)
i += 1
print("Your new list ", nlist)

nlist+[e]inputhere.append? That will force you to use some other, less efficient method that doesn't really add to understanding at all.[:index]+ desired item +[index:]