Q18Comprehension1.5 Marks28 Apr 2024
Passage
Consider a CSV file named employees.csv containing details of employees in a company. Note that the file has exactly 11 lines, and the entire file is given below for your reference:
department,name,position
HR,John Doe,Manager
Sales,Alice Smith,Sales Representative
IT,David Johnson,Software Engineer
HR,Jane Smith,HR Coordinator
IT,Michael Brown,Data Analyst
Sales,Sarah Lee,Sales Manager
IT,Chris Wilson,Software Engineer
HR,Emily Jones,Recruiter
Sales,Robert Garcia,Sales Associate
IT,Emma Taylor,Software Developer
Execute the following code given below and answer the two sub-questions that follow:
f = open('employees.csv', 'r')
f.readline() # read the header
employees = dict()
```
f = open('employees.csv', 'r')
f.readline() # read the header
employees = dict()
for line in f:
line = line.strip().split(',')
department, name, position = line
if department not in employees:
employees[department] = dict()
if name not in employees[department]:
employees[department][name] = position
f.close()
```
What is the output of the following snippet of code? Enter an integer as your answer.
print(len(employees['HR'].keys()))
Press Enter to check.