SimeonTs

SUPyF2 Dictionaries-Lab - 05. Word Synonyms

Oct 23rd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. """
  2. Dictionaries - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1736#4
  4.  
  5. SUPyF2 Dictionaries-Lab - 05. Word Synonyms
  6.  
  7. Problem:
  8. Write a program, which keeps a dictionary with synonyms.
  9. The key of the dictionary will be the word.
  10. The value will be a list of all the synonyms of that word.
  11. You will be given a number n – the count of the words.
  12. After each word, you will be given a synonym,
  13. so the count of lines you have to read from the console is 2 * n.
  14. You will be receiving a word and a synonym each on a separate line like this:
  15. • {word}
  16. • {synonym}
  17. If you get the same word twice, just add the new synonym to the list.
  18. Print the words in the following format:
  19. {word} - {synonym1, synonym2… synonymN}
  20. Examples:
  21. Input:
  22. 3
  23. cute
  24. adorable
  25. cute
  26. charming
  27. smart
  28. clever
  29.  
  30. Output:
  31. cute - adorable, charming
  32. smart - clever
  33.  
  34. Input:
  35. 2
  36. task
  37. problem
  38. task
  39. assignment
  40.  
  41. Output:
  42. task – problem, assignment
  43. """
  44. times = int(input())
  45. synonyms = {}
  46.  
  47. for how_ever_many_times in range(times):
  48.     word = input()
  49.     synonym = input()
  50.     if word not in synonyms:
  51.         synonyms[word] = [synonym]
  52.     else:
  53.         synonyms[word].append(synonym)
  54.  
  55. for word in synonyms:
  56.     print(F"{word} - {', '.join(synonyms[word])}")
Add Comment
Please, Sign In to add comment