Advertisement
bl00dt3ars

3

Aug 15th, 2021
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. my_dict = {}
  2.  
  3. my_words = input().split(' | ')
  4. for words in my_words:
  5.     word, definition = words.split(': ')
  6.     if word not in my_dict:
  7.         my_dict[word] = []
  8.     my_dict[word].append(definition)
  9.  
  10. teacher_words = input().split(' | ')
  11. command = input()
  12. if command == 'Test':
  13.     my_dict = {key: value for (key, value) in my_dict.items() if key in teacher_words}
  14.     for word, definitions in sorted(my_dict.items()):
  15.         print(f'{word}:')
  16.         for definition in sorted(definitions, key=lambda kvp: -len(kvp)):
  17.             print(f' -{definition}')
  18. else:
  19.     for word, definition in sorted(my_dict.items()):
  20.         print(word, end=' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement