From the course: Python: Programming Efficiently

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Analyze Olympic medalist data

Solution: Analyze Olympic medalist data - Python Tutorial

From the course: Python: Programming Efficiently

Start my 1-month free trial

Solution: Analyze Olympic medalist data

(upbeat music playing) - [Instructor] After loading the medalist dataset, we find the athletes with the most gold medals, with a straightforward applications of collections counter. We feed it the generator expression that extracts the names of athletes. We call the counter method most common to see those with the most gold around their neck. The best four our Paavo Nurmi, Carla Lewis, Usain Bolt an Ray Ewry. To find the athletes with medals in the most events, we need to collect a set of unique events won by every athlete. A default deque that provides an empty set as default seems appropriate. So we go through the medals to fill up the dict. Adding the event to the set for each athlete. Remember that in Python, you append to a list, but you add to a set. Then we down select the set with a dictionary comprehension that checks the number of events for each athlete. This is almost right, but Usain Bolt and Allyson…

Contents