Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Sorting Patient Records
00:00
5 left

Sorting Patient Records

EasyPython

Problem

Write a function to sort a list of patient records based on a specific field.

Implement sort_records(records, field). records is a list of dictionaries, and field is a key present in every dictionary. Return a new list sorted in ascending order by that field, without modifying the input list. If multiple records have the same value, preserve their original relative order.

Function signature: def sort_records(records, field):

Constraints

  • 0 <= len(records) <= 10^4
  • Each record is a dictionary
  • The selected field exists in every record
  • All values for the selected field are mutually comparable
  • The input list must not be modified

Function Signature

def sort_records(records, field):
Interviewer

Your question is Sorting Patient Records. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.