def split_list(self): while 1: print("---------------------------------------------------") print("1.Create List""\n""2. split list ""\n""3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int(input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create = UtilityDS.create_list_all(element) print("List is created : ", self.create) elif choice == 2: # if list is empty if len(self.create) == 0: print("List is empty..create list first.") # if list in not empty then perform split else: UtilityDS.split_word(self.create) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)
def difference_list(self): while 1: print("---------------------------------------------------") print("1.Create List" "\n" "2. Append List " "\n" "3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create1 = UtilityDS.create_list_all(element) print("create List 2 ----------- : ") self.create2 = UtilityDS.create_list_all(element) print("List 1 : ", self.create1) print("List 2 : ", self.create2) elif choice == 2: # if list is empty if len(self.create1) == 0 or len(self.create2) == 0: if len(self.create1) < 1: print("please create list 1") elif len(self.create2) < 1: print("please create list 2") else: print("List are empty..create list first.") # if list in not empty then display list appended else: append = UtilityDS.append_list( self.create1, self.create2) print("Appended list : ", append) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)
def longer_word(self): while 1: print("---------------------------------------------------") print("1.Create List" "\n" "2. Get words longer than N" "\n" "3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create = UtilityDS.create_list_all(element) print("List is created : ", self.create) elif choice == 2: # if list is empty if len(self.create) == 0: print("List is empty..create list first.") # if list in not empty then display list of word longer than Num else: num = int( input( "Enter the number to get longer words : ")) valid_num = UtilityDS.validate_num(num) if valid_num: n = UtilityDS.word_longer(self.create, num) print("Words longer than number : ", n) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)
def long_word(self): while 1: print("--------------------------------------------------") print("1.Create List of String" "\n" "2.Length of longest word." "\n" "3.Exit") try: choice = int(input("Enter choice :")) # validate choice ch = UtilityDS.validate_num(choice) if ch: if choice == 1: print("we are creating list : ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.str1 = UtilityDS.create_list_all(element) print("List is created : ", self.str1) elif choice == 2: if self.str1.__len__() < 1: print("Enter string first") else: # getting longest word from given list of string longest = UtilityDS.get_long_word(self.str1) print("Longest word in list of string is : ", longest) elif choice == 3: exit() else: print("Invalid choice") else: print("Enter choice between 1 - 3") except Exception as e: print(e)
def string_char(self): while 1: print("---------------------------------------------------") print("1.Create List" "\n" "2. Get Result " "\n" "3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list ") # number of element to add element = int( input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create = UtilityDS.create_list_all(element) print("List is created : ", self.create) elif choice == 2: # if list is empty if len(self.create) == 0: print("List is empty..create list first.") # if list in not empty then display smallest element else: # getting string which 1st char and last char is same result = UtilityDS.count_string_char(self.create) print( "Number of string whose FirstChar and LastChar are same : ", result) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)
def clone_list(self): while 1: print("---------------------------------------------------") print("1.Create List""\n""2. Create clone or copy""\n""3.Exit") try: choice = int(input("Enter any choice :")) # validating choice number ch = UtilityDS.validate_num(choice) if ch: # create list if choice == 1: print("we are creating list : ") # number of element to add element = int(input("How many element you want to add: ")) # validating the number e = UtilityDS.validate_num(element) if e: # if valid then create list self.create = UtilityDS.create_list_all(element) print("List is created : ", self.create) elif choice == 2: # if list is empty if len(self.create) == 0: print("List is empty..create list first.") # if list in not empty then display list after removal of duplicate else: copy = UtilityDS.clone_list(self.create) print("original list : ", self.create) print("Clone list is : ", copy) elif choice == 3: # exit from program exit() else: print("Invalid choice") except Exception as e: print(e)