AQR Capital Management interview question

Sorting and Python code refactor