Operations:
Creation of empty list
lst=[]
Insertion of element at start
1. start
2. a=input(“Enter element “)
[take input for element]
3. if(list is empty) then
append the element at end
else
insert element at 0 position
4. stop
#list #Create a Empty list lst=[] #add at start def addatstart(): a=input("Enter element to add at start ") if(len(lst)==0): lst.append(a) else: lst.insert(0,a) def addatend(): a=input("Enter element to add ") lst.append(a) def addatposition(): a=input("Enter the element to insert ") pos=int(input("Enter the position ")) lst.insert(pos-1,a) def display_all(): if(lst==[]): print("List is empty") else: print("List is\n") for i in lst: print(i,end=' ') def del_first(): if(lst==[]): print("List is empty") else: print("Deleted 1st element is ",lst[0]) lst.pop(0) def del_last(): if(lst==[]): print("List is empty") else: print("Deleted Last element is ",lst.pop()) def del_at_position(): pos=int(input("Enter the position ")) if(lst==[]): print("List is empty") else: print("Deleted element is ",lst.pop(pos-1)) def delete_all(): lst.clear() def search(): z=0 a=input("Enter the element to search ") if(lst==[]): print("List is empty") else: for i in lst: if(i==a): z=1 print("Element is present",) if z==0: print("Element is not present") def search_pos(): z=0 a=input("Enter the element to search ") if(lst==[]): print("List is empty") else: for i in range(0,len(lst)): if(lst[i]==a): z=1 print("Element is present at position ",i+1) if z==0: print("Element is not present") while True: print("\n\n\n1. Add at start ") print("2. Add at end ") print("3. Add at a position ") print("4. Display All") print("5. Delete 1st element ") print("6. Delete last element ") print("7. Delete by position ") print("8. Delete all elements ") print("9. search an element ") print("10. search and print position") print("0. Exit") ch=int(input("Enter your choice ")) if(ch==1): addatstart() elif(ch==2): addatend() elif(ch==3): addatposition() elif(ch==4): display_all() elif(ch==5): del_first() elif(ch==6): del_last() elif(ch==7): del_at_position() elif(ch==8): delete_all() elif(ch==9): search() elif(ch==10): search_pos() elif(ch==0): break else: print("Invalid choice ")