List


Combined  Program of List with all its functions


ch = 0
lst = []
while True :
    print("List Menu")
    print("1.Adding")
    print("2.Modify")
    print("3.Delete")
    print("4.Sort List")
    print("5.Display List")
    print("6.Exit")
    ch = int(input("Enter your choice : "))

    if ch == 1 :
      print("1.Add element")
      print("2.Add a List")
      print("3.Add a number")
      chi = int (input("Enter choice 1 or 2: "))
      if chi == 1:
            item = int(input("Enter element : "))
            pos = int(input("Enter position to add : "))
            lst.insert(pos, item)
      elif chi == 2 :
            addlist = eval (input ("Enter list : "))
            lst.extend(addlist)
      elif chi == 3:
            additem = eval (input ("Enter Item : "))
            lst.append(additem)
      else:
            print("Valid choices are 1 or 2")
      print("Successfully added")

    elif ch == 2 :
       pos = int (input("Enter position : "))
       item = int (input("Enter new value : "))
       old = lst[pos]
       lst[pos] = item
       print(old," modified with value ", item)

    elif ch == 3:
      print("1.Delete element by position")
      print("2.Delete element by value")
      chd = int(input("Enter you choice 1 or 2 "))
      if chd == 1:
            pos = int(input("Enter position : "))
            item = lst.pop(pos)
            print(item, " deleted ")
      elif chd == 2:
            item = int(input("Enter element: "))
            pos = lst.remove(item)
            print("Succcessfully deleted")
      else :
            print("Valid choices are 1 or 2")
    elif ch == 4 :
          print("l.Ascending")
          print("2.Descending")
          chs = int(input("Enter choice 1 or 2 "))
          if chs == 1:
            lst.sort()
          elif chs == 2:
            lst.sort(reverse = True)
          else :
            print("Valid choices are 1 or 2")

    elif ch == 5:
          print(lst)

    elif ch == 6:
          break

    else:
          print("Valid choices 1 to 6")