@extends('template') @section('title') Lab 11, Part 1: Ironman data @stop @section('content') # Lab 11, Part 1: Ironman data The Ironman race logo: a red circle on top of a red rectangel that has two triangular slots cut out of the bottom so that it resembles the letter M. In this part of lab, we are working with a subset of the results from the [2016 Ironman Triathlon](http://www.ironman.com/triathlon/events/americas/ironman/world-championship.aspx#/axzz4NN2nCF1d) race in Kona, Hawaii. This race has 3 parts, all completed in order, without a break: 1. A 2.4 mile (3.86 km) **swim** 2. A 112-mile (180.25 km) **bicycle ride** 3. A 26.22 miles (42.20 km) **marathon run** ## Task 0. Familiarize yourself with the data In your `lab11` folder there is a provided file called `kona.py` that contains a list of dictionaries, where each dictionary corresponds to one athlete. We are only looking at athletes in the 18-24 year old range. **Create a new file called `ironman.py` **— at the top of this file import `kona` so you can use the provided list of dictionaries: ```py from kona import kona ``` Here is a snapshot of what the list of dictionaries from `kona.py` looks like: ```py [{'bike': 6.32, 'country': 'CAN', 'divRank': '23', 'finish': 12.58, 'firstname': 'Morgan', 'genderRank': '506', 'lastname': 'Mcninch', 'overallRank': '1824', 'run': 4.58, 'swim': 1.17}, {'bike': 7.11, 'country': 'USA', 'divRank': '24', 'finish': 13.02, 'firstname': 'Mercedes', 'genderRank': '516', 'lastname': 'Decarli', 'overallRank': '1843', 'run': 4.3, 'swim': 1.1}, [...] {'bike': '---', 'country': 'AUS', 'divRank': '---', 'finish': 'DNF', 'firstname': 'Emily', 'genderRank': '---', 'lastname': 'Kempson', 'overallRank': '---', 'run': '---', 'swim': 1.04} ] ``` Notes about the data: + Each athlete's dictionary contains 10 `key:value` pairs that include their first and last name, country, finish time, overall rank, rank by gender, and their times for the run/bike/swim portions of the event. + Times were converted from a 3:17:23 format to a 3.17 where 3 is the number of hours and 17 is the minutes. Seconds were discarded from our data. + *Did Not Finish* + For the athletes that did not finish the race, the `finish` key has the value `DNF`, short for *Did Not Finish*. + For a DNF athlete, many of the key values (e.g., `divRank`, `run`, `bike`, `genderRank`) are a string of three dashes: `'---'`. At some point, you may have to handle the dictionaries of athletes who did not finish, so keep this in mind. ## Task 1. *printNames* - Print out all the athlete names Write a function called `printNames` that takes a list of dictionaries (e.g. the kona data) and **prints** the **first and last name** of each of the 69 athletes in the list. Example: ```py printNames(kona) ``` ```py Tungesvik,Hans Christian Hindkjaer,Kristian Kharin,Ivan [...] Talker,Elisa Fritz,Grant Kempson,Emily ``` ## Task 2. *printNamesCountry* - Print out all the athlete names from a particular country Write a function called `printNamesCountry` that takes a list of dictionaries (e.g. the kona data) *and* a 3 letter country abbrevation. This function should **print** the first and last name of each of the athletes from that country. __Example: Athletes from FRA:__ ```py printNamesCountry(kona, 'FRA') ``` ```py Tissot,Alexis Mennesson,William Philipps,Joachim Filleul,Valentine Pertsinidis,Nicolas ``` __Example: Athletes from AUS:__ ```py printNamesCountry(kona, 'AUS') ``` ```py Sansome,Kierra Gersekowski,Tom Jackson,Alexander Callaghan,Tom Wales,Lucy Kempson,Emily ``` ## Task 3. *getAllCountries* - Return unique countries Write a function called `getAllCountries` that takes a list of dictionaries (e.g. the kona data) and **returns** all unique countries represented at the Ironman race. Example: ```py print(getAllCountries(kona)) ``` ```py ['USA', 'SWE', 'GBR', 'CAN', 'BEL', 'PRI', 'FRA', 'CHE', 'LTU', 'ESP', 'DNK', 'AUS', 'AUT', 'FIN', 'NZL', 'JPN', 'ITA', 'BRA', 'ARG', 'RUS', 'MEX', 'NOR'] ``` (It's okay if your order does not match the example shown, just as long as all the values exist. There should be 22 unique countries represented across all athletes.) ## Task 4. *totalAthletesByCountry* - Return countries & athlete count Write a function called `totalAthletesByCountry` that takes a list of dictionaries (e.g. the kona data) and **returns** a dictionary where each key is a unique country, and the corresponding value is the total number of athletes from that country. Example: ```py print(totalAthletesByCountry(kona)) ``` Results: ```py {'USA': 22, 'SWE': 2, 'GBR': 1, 'CAN': 4, 'BEL': 1, 'PRI': 2, 'FRA': 5, 'CHE': 2, 'LTU': 1, 'ESP': 1, 'DNK': 6, 'AUS': 6, 'AUT': 2, 'FIN': 1, 'NZL': 2, 'JPN': 3, 'ITA': 1, 'BRA': 3, 'ARG': 1, 'RUS': 1, 'MEX': 1, 'NOR': 1} ``` (It's okay if your order does not match the example shown, just as long as all the values exist, because order does not matter in dictionaries.) There are different ways you could approach this task. @include('/labs/lab11/_toc') @stop