-
Notifications
You must be signed in to change notification settings - Fork 253
Student Directory
Sar Champagne Bielert edited this page Apr 7, 2024
·
4 revisions
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Create a dictionary from a list of keys (student names) and generate a unique ID for each value.
1) Create a new, empty dict
2) The current student ID starts at 1
3) For each student name:
a) In the new dict, map name -> current ID
b) Increment current ID by one
4) Return the new dict
def student_directory(student_names):
student_dict = {}
student_id = 1 # Start student IDs at 1
for name in student_names:
student_dict[name] = student_id
student_id += 1
return student_dict