Black_Rabbit

Inheritance_errors

Nov 16th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. exception_list, exception_names, final_list = [], [], []
  2. dict_exceptions = {}    
  3. number_of_exception_classes = int(input())
  4.  
  5.  
  6. def get_parent_exception(checked_exception, list_exception_names, dict_exceptions, len_list_exception_names):
  7.     if dict_exceptions[checked_exception] == ['object']:
  8.         return False
  9.  
  10.     for i in range(len_list_exception_names):
  11.         if list_exception_names[i] in dict_exceptions[checked_exception]:
  12.             return True
  13.  
  14.     if len(dict_exceptions[checked_exception]) == 1:
  15.         if get_parent_exception(dict_exceptions[checked_exception][0], list_exception_names, dict_exceptions, len_list_exception_names):
  16.             return True
  17.         else:
  18.             return False
  19.  
  20.     elif len(dict_exceptions[checked_exception]) > 1:
  21.         if __rec__(dict_exceptions[checked_exception], list_exception_names, dict_exceptions, len_list_exception_names):
  22.             return True
  23.         else:
  24.             return False
  25.  
  26.  
  27. def __rec__(checked_exception, list_exception_names, dict_exceptions, len_list_exception_names):
  28.     for i in checked_exception:
  29.         if get_parent_exception(i, list_exception_names, dict_exceptions, len_list_exception_names):
  30.             return True
  31.         else:
  32.             continue
  33.     return False
  34.  
  35.  
  36. for i in range(number_of_exception_classes):
  37.     inherited_classes = input().split()
  38.     len_inherited_classes = len(inherited_classes)
  39.     if len_inherited_classes > 2:  
  40.         for j in range(len_inherited_classes-2):
  41.             exception_list.append(inherited_classes[2+j])
  42.         dict_exceptions[inherited_classes[0]] = exception_list  
  43.         exception_list = []
  44.     else:
  45.         dict_exceptions[inherited_classes[0]] = ['object']  
  46.  
  47.  
  48. number_of_exceptions_handled = int(input())
  49. for value in range(number_of_exceptions_handled):
  50.     exception_names.append(input())
  51.     if value == 0:
  52.         continue
  53.     elif get_parent_exception(exception_names[value], exception_names, dict_exceptions, value):
  54.         if exception_names[value] not in final_list:
  55.             final_list.append(exception_names[value])
  56.             print(exception_names[value])
  57.         else:
  58.             continue
  59.     else:
  60.         continue
Add Comment
Please, Sign In to add comment