Advertisement
GeorgiLukanov87

03. Dictionary final exam 100/100

Aug 7th, 2022
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. # 03. Dictionary - Final exam 100/100
  2.  
  3. ====================================================================================================================
  4.  
  5. # var 1
  6.  
  7.  
  8. data = input().split(' | ')
  9. my_dict = {}
  10.  
  11. for current_word in data:
  12.     current_word = current_word.split(': ')
  13.     word = current_word[0]
  14.     definition = current_word[1]
  15.     if word not in my_dict.keys():
  16.         my_dict[word] = []
  17.         my_dict[word].append(definition)
  18.     elif word in my_dict.keys() and definition not in my_dict.values():
  19.         my_dict[word].append(definition)
  20.  
  21. teacher_words = input().split(' | ')
  22. command = input()
  23.  
  24. if command == 'Test':
  25.     for searched_key in teacher_words:
  26.         if searched_key in my_dict.keys():
  27.             print(f'{searched_key}:')
  28.             for key_word in my_dict[searched_key]:
  29.                 print(f' -{key_word}')
  30.  
  31. elif command == 'Hand Over':
  32.     for key_word in my_dict:
  33.         print(key_word, end=' ')
  34.  
  35.  
  36. ====================================================================================================================
  37.  
  38. # var 2 functions
  39.  
  40.  
  41. def final_print_func(some_words, some_command, some_dict):
  42.     if some_command == 'Test':
  43.         for searched_key in some_words:
  44.             if searched_key in some_dict.keys():
  45.                 print(f'{searched_key}:')
  46.                 for key_word in some_dict[searched_key]:
  47.                     print(f' -{key_word}')
  48.     elif command == 'Hand Over':
  49.         for key_word in some_dict:
  50.             print(key_word, end=' ')
  51.  
  52.  
  53. def create_initial_dict_func():
  54.     data = input().split(' | ')
  55.     initial_dict = {}
  56.     for current_word in data:
  57.         current_word = current_word.split(': ')
  58.         word = current_word[0]
  59.         definition = current_word[1]
  60.         if word not in initial_dict.keys():
  61.             initial_dict[word] = []
  62.             initial_dict[word].append(definition)
  63.         elif word in initial_dict.keys() and definition not in initial_dict.values():
  64.             initial_dict[word].append(definition)
  65.     return initial_dict
  66.  
  67.  
  68. my_dict = create_initial_dict_func()
  69. teacher_words = input().split(' | ')
  70. command = input()
  71. final_print_func(teacher_words, command, my_dict)
  72.  
  73.  
  74. ====================================================================================================================
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement