Level 5Exercise #123
Read nested attributes
Return objects ordered by profile.score descending.
What you’ll practice
This Level 5 exercise focuses on operator.attrgetter in the Algorithms curriculum. Solve the challenge prompt above using clear, idiomatic Python and the relevant language or standard-library tools.
Relevant Python reference: operator — Standard operators as functions.
Sample Test Cases
Example #1
Input:
(lambda: (User := __import__('collections').namedtuple('User', ['profile']), Profile := __import__('collections').namedtuple('Profile', ['score']), [u.profile.score for u in rank_profiles([User(Profile(50)), User(Profile(90))])])[2])()Output:
highest score firstFurther Reading
Reference Solution
Reveal Reference Solution
def rank_profiles(users: list) -> list: from operator import attrgetter return sorted(users, key=attrgetter('profile.score'), reverse=True)Pro Tips & Keyboard Shortcuts
Color Theme
Ctrl + K then T
Open VS Code Color Theme Quick Pick to select from 20 dark and light themes.
Editor SettingsCtrl + K
Open practice settings drawer to toggle line numbers, indenting, font size & hints.
Search MenuCtrl + /
Expand sidebar menu, focus search bar, and highlight search text instantly.
Focus Code Editor
Esc or Ctrl + `
Instantly highlight and focus code editor from anywhere, restoring cursor right where you left off.
Normal ViewEsc
Collapse sidebar and close all popups or settings drawers for clean focus view.