SimeonTs

SUPyF2 Dict-Exercise - 08. Company Users

Oct 24th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. """
  2. Dictionaries - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1737#7
  4.  
  5. SUPyF2 Dict-Exercise - 08. Company Users
  6.  
  7. Problem:
  8. Write a program that keeps information about companies and their employees.
  9. You will be receiving a company name and an employee's id, until you receive the command "End" command.
  10. Add each employee to the given company. Keep in mind that a company cannot have two employees with the same id.
  11. When you finish reading the data, order the companies by the name in ascending order.
  12. Print the company name and each employee's id in the following format:
  13. {companyName}
  14. -- {id1}
  15. -- {id2}
  16. -- {idN}
  17. Input / Constraints
  18. • Until you receive the "End" command, you will be receiving input in the format: "{companyName} -> {employeeId}".
  19. • The input always will be valid.
  20.  
  21. Examples:
  22. Input:
  23. SoftUni -> AA12345
  24. SoftUni -> BB12345
  25. Microsoft -> CC12345
  26. HP -> BB12345
  27. End
  28.  
  29. Output:
  30. HP
  31. -- BB12345
  32. Microsoft
  33. -- CC12345
  34. SoftUni
  35. -- AA12345
  36. -- BB12345
  37.  
  38. Input:
  39. SoftUni -> AA12345
  40. SoftUni -> CC12344
  41. Lenovo -> XX23456
  42. SoftUni -> AA12345
  43. Movement -> DD11111
  44. End
  45.  
  46. Output:
  47. Lenovo
  48. -- XX23456
  49. Movement
  50. -- DD11111
  51. SoftUni
  52. -- AA12345
  53. -- CC12344
  54. """
  55.  
  56. companies = {}
  57.  
  58. while True:
  59.     command = input()
  60.     if command == "End":
  61.         break
  62.     company, employee_id = command.split(" -> ")
  63.     if company not in companies:
  64.         companies[company] = [employee_id]
  65.     else:
  66.         if employee_id not in companies[company]:
  67.             companies[company] += [employee_id]
  68.  
  69. for company, employees in sorted(companies.items()):
  70.     print(f"{company}")
  71.     for employee in employees:
  72.         print(f"-- {employee}")
Add Comment
Please, Sign In to add comment