Example #1
0
    def multiply_list(self):
        while 1:
            print("1.Create List"
                  "\n"
                  "2.Multiplication of element "
                  "\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
                            create = UtilityDS.create_list(element)
                            print("List is created : ", create)
                    elif choice == 2:
                        # display sum of the list element
                        mul_list = UtilityDS.multiplication_list(create)
                        print("Multiplication of items : ", mul_list)
                    elif choice == 3:
                        # exit from program
                        exit()

            except Exception as e:
                print(e)
Example #2
0
    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 unique_val(self):
     sample = [{"V": "S001"}, {"V": "S002"},
               {"VI": "S001"}, {"VI": "S005"},
               {"VII": "S005"}, {"V": "S009"}, {"VIII": "S007"}]
     print("Original data : ", sample)
     while 1:
         try:
             print("1: Find unique values in dictionary ""\n""2: Original dictionary""\n""3: Exit")
             ch = int(input("Enter your choice: "))
             # validate choice number
             choice = UtilityDS.validate_num(ch)
             if choice:
                 if ch == 1:
                     # get all unique values in dictionary
                     unique_data = UtilityDS.unique_values(sample)
                     print("Unique value in dictionary : ", unique_data)
                 elif ch == 2:
                     # get original dictionary
                     print("Original Dictionary : ", sample)
                 elif ch == 3:
                     exit()
                 else:
                     print("please enter valid choice")
             else:
                 # if entered literals except int
                 print("please enter number only")
         except Exception as e:
             print(e)
Example #4
0
    def split_list(self):
        while 1:
            print("---------------------------------------------------")
            print("1.split list " "\n" "2.Exit")
            try:
                choice = int(input("Enter any choice :"))
                # validating choice number
                ch = UtilityDS.validate_num(choice)
                if ch:
                    # create list
                    if choice == 1:
                        # if list is empty
                        if len(self.create) == 0:
                            print("List is empty..create list first.")
                        # if list in not empty then perform remove duplicate from list of list
                        else:
                            print("original list : ", self.create)
                            item = UtilityDS.list_to_list(self.create)
                            print("Removed duplicates in list of list : ",
                                  item)
                    elif choice == 2:
                        # exit from program
                        exit()
                    else:
                        print("Invalid choice")

            except Exception as e:
                print(e)
Example #5
0
 def generate_script(self):
     while 1:
         try:
             print("Enter your choice:")
             input_text = int(
                 input("1: Generate Script"
                       "\n"
                       "2:Exit"
                       " : "))
             # exit the program when choice is 2("Exit")
             if input_text == 2:
                 exit()
             # else generate script and print dictionary
             elif input_text == 1:
                 num = int(input("\n" "Enter any Positiver number : "))
                 # validate number
                 sample = UtilityDS.validate_num(num)
                 if sample:
                     # if number is valid then call function for generating script
                     script = UtilityDS.script_generate1(num)
                     print(script)
                 else:
                     print("Enter valid number to generate script")
             # display message when you entered invalid choice
             else:
                 print("You entered wrong choice")
         except ValueError:
             print("error value error")
Example #6
0
 def remove(self):
     print("Tuple : ", self.tuple1)
     while True:
         try:
             print("1. Remove Item" "\n" "2. View Tuple" "\n" "3.Exit")
             choice = int(input("Enter your choice : "))
             # validate choice number
             ch = UtilityDS.validate_num(choice)
             if ch:
                 # choice to remove item
                 if choice == 1:
                     item = int(input("Enter items to be remove : "))
                     rm = UtilityDS.remove_tuple(self.tuple1, item)
                     print("After removing item : ", rm)
                 # choice to display tuple element
                 elif choice == 2:
                     print("Tuple : ", self.tuple1)
                 # exiting from program
                 elif choice == 3:
                     print("Exiting...")
                     exit()
                 else:
                     print("Invalid choice" "\n")
             else:
                 print("Enter only number" "\n")
         except Exception as e:
             # raise and print exception
             print(e)
Example #7
0
 def count_substring(self):
     while 1:
         print("--------------------------------------------------")
         print("1.Enter substring input"
               "\n"
               "2.Get count of substring"
               "\n"
               "3.Exit")
         try:
             choice = int(input("Enter choice :"))
             # validate choice
             ch = UtilityDS.validate_num(choice)
             if ch:
                 if choice == 1:
                     # getting substring
                     sub_str = input(
                         "which sub string you want to count : ")
                     print("substring is : ", sub_str)
                 elif choice == 2:
                     # get count of substring in string
                     output = UtilityDS.count_substring(sub_str)
                     print("Count of substring : ", output)
                 elif choice == 3:
                     exit()
                 else:
                     print("Invalid choice")
             else:
                 print("Enter choice between 1 - 3")
         except Exception as e:
             print(e)
Example #8
0
    def sort_list(self):
        while 1:
            print("---------------------------------------------------")
            print("1.View List""\n""2.Get Sorted 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:
                        self.create = [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
                        print("List is : ", 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.print_sort_list(self.create)
                            print("List in increasing order by LastName in each tuple  : ", result)
                    elif choice == 3:
                        # exit from program
                        exit()
                    else:
                        print("Invalid choice")
                else:
                    print("Enter number for choice")

            except Exception as e:
                print(e)
Example #9
0
 def calculate_len(self):
     while 1:
         print("--------------------------------------------------")
         print("1.Enter String" "\n" "2.Calculate length" "\n" "3.Exit")
         try:
             choice = int(input("Enter choice :"))
             # validate choice
             ch = UtilityDS.validate_num(choice)
             if ch:
                 if choice == 1:
                     # create string
                     self.str1 = input("Enter Any string : ")
                     # validate string
                     valid = UtilityDS.validate_string(self.str1)
                     if valid:
                         print()
                     else:
                         print("Enter only string")
                 elif choice == 2:
                     if self.str1.__len__() < 1:
                         print("Enter string first")
                     else:
                         # get length of string
                         str_len = UtilityDS.str_len(self.str1)
                         print("Length of string is: ", str_len)
                 elif choice == 3:
                     exit()
                 else:
                     print("Invalid choice")
             else:
                 print("Enter choice between 1 - 3")
         except Exception as e:
             print(e)
    def sum_list(self):
        while 1:
            print("1.Create List""\n""2.Sum of 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(element)
                            print("List is created : ", self.create)
                    elif choice == 2:
                        if len(self.create) < 1:
                            print("create list first")
                        else:
                            # display sum of the list element
                            sum_list = UtilityDS.sum_list(self.create)
                            print("Sum of list : ", sum_list)
                    elif choice == 3:
                        # exit from program
                        exit()

            except Exception as e:
                print(e)
Example #11
0
 def upper_lower(self):
     while 1:
         print("--------------------------------------------------")
         print("1.Enter string input""\n""2.Get result in UPPER/lower Case.""\n""3.Exit")
         try:
             choice = int(input("Enter choice :"))
             # validate choice
             ch = UtilityDS.validate_num(choice)
             if ch:
                 if choice == 1:
                     # create string
                     self.str1 = input("Enter Any string : ")
                     # validate string
                     valid = UtilityDS.validate_string(self.str1)
                     if valid:
                         print()
                     else:
                         print("Enter only string")
                 elif choice == 2:
                     if self.str1.__len__() < 1:
                         print("Enter string first")
                     else:
                         # get string output in UPPER/lower Case
                         output = UtilityDS.upper_lower(self.str1)
                         print("Upper and Lower Case String : ", output)
                 elif choice == 3:
                     exit()
                 else:
                     print("Invalid choice")
             else:
                 print("Enter choice between 1 - 3")
         except Exception as e:
             print(e)
 def format_string(self):
     while 1:
         print("--------------------------------------------------")
         print("1.Display String""\n""2.Get format result""\n""3.Exit")
         try:
             choice = int(input("Enter choice :"))
             # validate choice
             ch = UtilityDS.validate_num(choice)
             if ch:
                 if choice == 1:
                     print("The String : ", self.string)
                 elif choice == 2:
                     if self.string.__len__() < 1:
                         print("Enter string first")
                     else:
                         # get formatted result of string
                         result = UtilityDS.format_string(self.string)
                         print(result)
                 elif choice == 3:
                     exit()
                 else:
                     print("Invalid choice")
             else:
                 print("Enter choice between 1 - 3")
         except Exception as e:
             print(e)
Example #13
0
    def difference_list(self):
        while 1:
            print("---------------------------------------------------")
            print("1.Create List"
                  "\n"
                  "2. Calculate difference b/w lists"
                  "\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(element)
                            print("List 2 create : ")
                            self.create2 = UtilityDS.create_list(element)
                            print("List is created : ", 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 difference b/w list
                        else:
                            diff = UtilityDS.get_diff_list(
                                self.create1, self.create2)
                            print("difference in lists : ", diff)
                    elif choice == 3:
                        # exit from program
                        exit()
                    else:
                        print("Invalid choice")

            except Exception as e:
                print(e)
Example #14
0
 def lower_case(self):
     while 1:
         print("--------------------------------------------------")
         print("1.Enter string "
               "\n"
               "2.String with lowercase of n char"
               "\n"
               "3.Exit")
         try:
             choice = int(input("Enter choice :"))
             # validate choice
             ch = UtilityDS.validate_num(choice)
             if ch:
                 if choice == 1:
                     # create string
                     self.str1 = input("Enter string in Upper Case Only : ")
                     # validate string
                     valid = UtilityDS.validate_string(self.str1)
                     if valid:
                         print()
                     else:
                         print("Enter only string")
                 elif choice == 2:
                     if self.str1.__len__() < 1:
                         print("Enter string first")
                     else:
                         print("String is : ", self.str1)
                         n = int(
                             input(
                                 "Enter N length to get lowercase letter :")
                         )
                         # validate N length number
                         num = UtilityDS.validate_num(n)
                         if num:
                             # get string with lowercase letter of n char
                             output = UtilityDS.get_lowercase(self.str1, n)
                             print("Letter with lowercase of 1st N char : ",
                                   output)
                         else:
                             print("please enter number only")
                 elif choice == 3:
                     exit()
                 else:
                     print("Invalid choice")
             else:
                 print("Enter choice between 1 - 3")
         except Exception as e:
             print(e)
 def count_items(self):
     try:
         print("Items in dictionary :", self.d.values())
         # get number of items in dictionary value that is list
         count = UtilityDS.count_items_dict(self.d)
         print("Number of items in dictionary value is : ", count)
     except Exception as e:
         print(e)
Example #16
0
 def convert(self):
     try:
         print("Original List : ", self.list_name)
         # calling function for convert list to nested dictionary of keys
         convert_list = UtilityDS.list_to_dict(self.list_name)
         print("Nested Dictionary of keys", convert_list)
     except Exception as e:
         print(e)
 def slicing(self):
     try:
         print("Tuple : ", self.tuple1)
         # get slicing tuple
         sl = UtilityDS.slice_tuple(self.tuple1)
         print("Slicing tuple :", sl)
     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)
Example #19
0
    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)
Example #20
0
    def common_member(self):
        while 1:
            print("---------------------------------------------------")
            print("1.Create List" "\n" "2. Get common member 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.create1 = UtilityDS.create_list(element)
                            print("creating list 2:")
                            self.create2 = UtilityDS.create_list(element)
                            print("List 1 is created : ", self.create1)
                            print("List 2 is created : ", 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 , display list of word longer than Num
                        else:
                            common = UtilityDS.common_member(
                                self.create1, self.create2)
                            print("Common members are : ", common)
                    elif choice == 3:
                        # exit from program
                        exit()
                    else:
                        print("Invalid choice")

            except Exception as e:
                print(e)
 def count_value(self):
     print("Dictionary : ", self.d)
     try:
         # calling function from Utility module to get no. of value associated with key
         dictionary = UtilityDS.count_key_values(self.d)
         print("Number of dictionary have success True: ", dictionary)
     except Exception as e:
         print(e)
 def unpack_tuple(self):
     try:
         print("Packed tuple : ", self.tuple1)
         # unpacking tuple
         unpack = UtilityDS.unpack_tuple(self.tuple1)
         print("Unpacking tuple : ", unpack)
         u1, u2, u3, u4 = self.tuple1
     except Exception:
         print("Should have enough value to unpack ")
 def add_key(self):
     try:
         dict = {1: 10, 2: 10}
         print("Original dictionary :", dict)
         # function call for adding key to dictionary
         k = UtilityDS.add_key_dictionary(dict)
         print("After adding key : ", k)
     except Exception as e:
         print(e)
Example #24
0
 def dict_create(self):
     try:
         str1 = "independent47"
         print("The String is : ", str1)
         # calling function to convert string into dictionary
         get_value = UtilityDS.create_dict(str1)
         print("converted string into dictionary : ", get_value)
     except Exception as e:
         print(e)
Example #25
0
 def reverse_tuple(self):
     try:
         # original tuple
         print("Original Tuple : ", self.tuple1)
         # getting reverse tuple
         rev = UtilityDS.rev_tuple(self.tuple1)
         # display reverse tuple
         print("Reverse Tuple : ", rev)
     except Exception as e:
         print(e)
Example #26
0
 def sort_unique_word(self):
     while 1:
         print("--------------------------------------------------")
         print("1.Get unique word in sorted manner" "\n" "2.Exit")
         try:
             choice = int(input("Enter choice :"))
             # validate choice
             ch = UtilityDS.validate_num(choice)
             if ch:
                 if choice == 1:
                     # get word in sorted manner
                     output = UtilityDS.sort_word()
                     print("Unique word in sorted way : ", output)
                 elif choice == 2:
                     exit()
                 else:
                     print("Invalid choice")
             else:
                 print("Enter choice between 1 - 3")
         except Exception as e:
             print(e)
Example #27
0
 def repeat_items(self):
     try:
         print("Tuple1 : ", self.tuple1)
         # function call  to check whether item repeated or not
         find = UtilityDS.get_repeat_items(self.tuple1)
         if find:
             # if repeat item found
             print("Items is repeated : ", find)
         else:
             print("No items are repeated")
     except Exception as e:
         print(e)
    def get_last_part(self):
        while 1:
            print("--------------------------------------------------")
            print("1.Get String Result" "\n" "2.Exit")
            try:
                choice = int(input("Enter choice :"))
                # validate choice
                ch = UtilityDS.validate_num(choice)
                if ch:
                    if choice == 1:
                        # get last part of string before specified char
                        UtilityDS.last_part_string()

                    elif choice == 2:
                        exit()
                    else:
                        print("Invalid choice")
                else:
                    print("Enter choice between 1 - 3")
            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)