Advertisement
horozov86

Final Exam Fundamentals - Dictionaries

Apr 2nd, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. words_definitions = input()
  2.  
  3. dictionary = {}
  4. words_definitions_split = words_definitions.split(" | ")
  5. for word_definition in words_definitions_split:
  6.     word_definition_split = word_definition.split(": ")
  7.     word = word_definition_split[0]
  8.     definition = word_definition_split[1]
  9.  
  10.     if word not in dictionary:
  11.         dictionary[word] = []
  12.         dictionary[word].append(definition)
  13.     else:
  14.         dictionary[word].append(definition)
  15.  
  16.  
  17. only_word = input()
  18. only_word_split = only_word.split(" | ")
  19. command = input()
  20. for el in only_word_split: # изкарвами думите, които се подават
  21.     if command == "Test":
  22.         if el in dictionary:
  23.             print(f"{el}:")
  24.             for definition in (dictionary[el]):
  25.                 print(f" -{definition}")
  26.  
  27.     else:
  28.         for word in dictionary.keys():
  29.             print(word, end=" ")
  30.         exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement