Lab 9, Part 2: 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 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 lab09 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:

from kona import kona

Here is a snapshot of what the list of dictionaries from kona.py looks like:

[
    {'swim': 0.95, 'finish': 9.433333333333334, 'run': 3.283333333333333, 'firstname': 'Hans Christian', 'lastname': 'Tungesvik', 'genderRank': '128', 'overallRank': '137', 'bike': 5.083333333333333, 'country': 'NOR', 'divRank': '1'},
    {'swim': 0.95, 'finish': 9.516666666666667, 'run': 3.4833333333333334, 'firstname': 'Kristian', 'lastname': 'Hindkjaer', 'genderRank': '159', 'overallRank': '169', 'bike': 4.933333333333333, 'country': 'DNK', 'divRank': '2'},
    {'swim': 1.05, 'finish': 9.533333333333333, 'run': 3.35, 'firstname': 'Ivan', 'lastname': 'Kharin', 'genderRank': '172', 'overallRank': '183', 'bike': 5.0, 'country': 'RUS', 'divRank': '3'},

[...]

    {'swim': 1.0666666666666667, 'finish': 'DNF', 'run': '---', 'firstname': 'Emily', 'lastname': 'Kempson', 'genderRank': '---', 'overallRank': '---', 'bike': '---', 'country': 'AUS', 'divRank': '---'},
]

Notes about the data:

Task 1. printNames - Print out all the athlete names

Partner A

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:

printNames(kona)
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

Partner B

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:

printNamesCountry(kona, 'FRA')
Tissot,Alexis
Mennesson,William
Philipps,Joachim
Filleul,Valentine
Pertsinidis,Nicolas

Example: Athletes from AUS:

printNamesCountry(kona, 'AUS')
Sansome,Kierra
Gersekowski,Tom
Jackson,Alexander
Callaghan,Tom
Wales,Lucy
Kempson,Emily

Task 3. getAllCountries - Return unique countries

Partner A

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:

print(getAllCountries(kona))
['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

Partner B

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:

print(totalAthletesByCountry(kona))

Results:

{'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.

Task 5. buildDictWithAverageEventTimes - Average event times for each country's athletes.

Partner A

Write a function called buildDictWithAverageEventTimes that...

Example:

print(buildDictWithAverageEventTimes(kona))
# Note: Line breaks have been added for readability
{
    'NOR': {'swim': 0.95, 'bike': 5.08, 'run': 3.28},
    'DNK': {'swim': 1.12, 'bike': 5.46, 'run': 3.65},
    'RUS': {'swim': 1.05, 'bike': 5.0, 'run': 3.35},
    'NZL': {'swim': 1.14, 'bike': 5.88, 'run': 3.71},
    'BRA': {'swim': 0.99, 'bike': 5.45, 'run': 3.77},
    'FIN': {'swim': 0.88, 'bike': 5.05, 'run': 3.7},
    'FRA': {'swim': 1.03, 'bike': 5.45, 'run': 3.85},
    'CHE': {'swim': 1.03, 'bike': 5.51, 'run': 4.06},
    'USA': {'swim': 1.06, 'bike': 5.86, 'run': 4.23},
    'CAN': {'swim': 1.15, 'bike': 6.03, 'run': 4.35},
    'AUT': {'swim': 1.21, 'bike': 6.48, 'run': 5.1},
    'MEX': {'swim': 1.05, 'bike': 5.92, 'run': 3.35},
    'ITA': {'swim': 1.08, 'bike': 5.65, 'run': 3.75},
    'GBR': {'swim': 1.13, 'bike': 5.7, 'run': 3.65},
    'AUS': {'swim': 0.88, 'bike': 4.87, 'run': 3.57},
    'PRI': {'swim': 1.14, 'bike': 6.02, 'run': 4.79},
    'JPN': {'swim': 1.17, 'bike': 6.1, 'run': 4.67},
    'LTU': {'swim': 1.0, 'bike': 5.75, 'run': 4.35},
    'ARG': {'swim': 1.1, 'bike': 6.18, 'run': 4.2},
    'SWE': {'swim': 1.23, 'bike': 6.85, 'run': 4.88},
    'BEL': {'swim': 0.88, 'bike': 5.1, 'run': 6.8},
    'ESP': {'swim': 1.35, 'bike': 7.7, 'run': 4.55}
}

The resulting dictionary should have 22 elements.

It's okay if your order does not match the example shown, just as long as all the values exist. It's also fine if your values are slightly different: there are different approaches to the DNF entries that result in different values.

Tips:

Table of Contents