A Function to Perform Operations on a List
'''
A Simle Python Program to manipulate a list
without the user needing to know about the
functions required to do so.
'''
def list_manipulator(ls):
'''A python function to manipulate a given list by asking
the user for inputs'''
N:int=int(input("Enter the number of operations you want
to perform on the list. "))
for _ in range(N):
ls1=input("Enter your choice please. ").strip().split()
choice=ls1[0]
if choice=="insert":
'''Here b is the element and a is the position
on which the elem a is to be inserted'''
a:int=int(ls1[1])
b:int=int(ls1[2])
ls.insert(a,b)
elif choice=="pop":
ls.pop()
elif choice=="print":
print(*ls)
elif choice=="remove":
b1:int=int(ls1[1])
ls.remove(b1)
elif choice=="sort":
ls.sort()
elif choice=="reverse":
ls.reverse()
elif choice=="append":
b2:int=int(ls1[1])
ls.append
else:
print("Wrong choice!!")
def main():
lis=[]
list_manipulator(lis)
print("The list after using list manipulator is",*lis)
if __name__=="__main__":
main()
Comments
Post a Comment