Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
NBA Stats Application
The Helper Function
Core Functions
9. Sorting clubs
Menu Functions
Putting it all together


Great! Now that we have the helper functions in place, let's get down to writing the core functions that will be sorting players, picking the best player, or checking the relationship between a player and a club.

We'll start with a function that will sort players by a given parameter.


Create a function named sort_players(players, key_index). The function should return a copy of the players list that has been sorted by a given key. Do not modify the original list.

The key is an integer that denotes which tuple element index should be used for sorting. Remember, each player is represented by a tuple in the following format:

(firstname, lastname, height, matches_played, fg, current_club, former_clubs)

Stuck? Here's a hint!

Import and use the itemgetter() function:

from operator import itemgetter