Removing or Modifying the Exceptions during runtime
Modifying Exceptions During Runtime: Suppose there is a Registration Form. If you got exceptional data in the form like in the place of Name you got phone numbers to remove that ambiguity from the data we use the following logical abstraction without any explicit coding(if-else ladder) not only for registration form can be applied to DBMS Data and also various Datasets.
Exceptional Data: The Data is said to be exceptional when data is incorrect or does not belong to the same group. this data is also called ambiguous data to remove this ambiguity in the data some operations needed to be performed. removing exceptional data from the list reduces errors or exceptions while performing operations.
Example: String operations cannot be done on the entire list, because it also has numerical. If we do so exceptions will be raised. So, to avoid exceptions, partition the data in the array into their respective data type.
Convert elements of a list to uppercase.
Input: names = [‘geeks’, ‘for’, ‘geeks’, ‘is’, ‘best’, 9876543210, 3.142, 5 + 8j, True], convert strings in the list to uppercase and remove unwanted data.
Output: [‘GEEKS’, ‘FOR’, ‘GEEKS’, ‘IS’, ‘BEST’][9876543210, 3.142, 5 + 8j, True]
Recursive Approach: By removing the exceptional data from the list using exception handling.
#update/remove exceptional data
- Input: Arr
- Initialize exceptional_data = , Index = 0.
- Iterate over arr and apply uppercase operation on the data in try block to find exceptional data.
while(index < len(names)):
names[index] = names[index].upper()
index += 1
- If exceptional data found, store it in exceptional_data list and remove that data from list. and again call function with new list and index
exception = names.pop(index)
- After looping return arr
Below is the Implementation of the above approach:
Exceptional data: ['geeks', 'for', 'geeks', 'is', 'best', 9876543210, 3.142, (5+8j), True] Uppercase data : ['GEEKS', 'FOR', 'GEEKS', 'IS', 'BEST'] Exceptional data: [9876543210, 3.142, (5+8j), True]
Time Complexity: O(n), where n is the length of the arr.
Auxiliary Space: O(1).
Advantages of Modifying the Exceptions during runtime:
- Respective operations on the respective list are done easily without explicit coding.
- Data is partitioned easily.
- Exceptions are handled easily and also reduced.
- The Time complexity is also efficient.
- It also can be used to handle larger data in datasets.
Please Login to comment...