Issue with 8. Company Users
Здравейте. Имам проблем със задача 8 от Exercise: Dictionaries.
Нулевите тестове преминават, но в някои от останалите кодът се чупи и получавам 50/100.
Това е условието:
8.Company Users
Write a program that keeps information about companies and their employees.
You will be receiving a company name and an employee's id, until you receive the command "End" command. Add each employee to the given company. Keep in mind that a company cannot have two employees with the same id.
When you finish reading the data, order the companies by the name in ascending order.
Print the company name and each employee's id in the following format:
{companyName}
-- {id1}
-- {id2}
-- {idN}
Input / Constraints
- Until you receive the "End" command, you will be receiving input in the format: "{companyName} -> {employeeId}".
- The input always will be valid.
Examples
Output |
|
SoftUni -> AA12345 SoftUni -> BB12345 Microsoft -> CC12345 HP -> BB12345 End |
HP -- BB12345 Microsoft -- CC12345 SoftUni -- AA12345 -- BB12345 |
SoftUni -> AA12345 SoftUni -> CC12344 Lenovo -> XX23456 SoftUni -> AA12345 Movement -> DD11111 End |
Lenovo -- XX23456 Movement -- DD11111 SoftUni -- AA12345 -- CC12344 |
А това е моят код:
text = input()
companies = {}
while text != 'End':
text_spl = text.split(' -> ')
company = text_spl[0]
employee = text_spl[1]
if company not in companies:
companies[company] = []
companies[company].append(employee)
text = input()
companies = dict(sorted(companies.items(), key=lambda x: x[0]))
for key, employee in companies.items():
print(f'{key}')
for name in sorted(set(employee)):
print(f'-- {name}')
Благодаря предварително за помощта!
Поздрави,
Мартин
Много благодаря!