A 100m race¶
Save all functions into a file named race.py.
The results of a 100 meters races season are stored into a nested
list. Each element of the main list is a sublist with the information corresponding to a male athlete: his name (str) and one or more values (float) that correspond to the times in seconds he has made in all 100 m races during this season.Write the function
min_time()that takes alistas described in the previous paragraph, and returns anotherlistwith the season minimum time for each athlete. This list must be sorted increasingly. See the following examples:>>> ltime = [['Bolt',9.74,9.82,9.58,10.02],['Carter',10.05,10.0,9.91], ... ['Powell',9.93,9.9,9.74],['Gatlin',10.01,9.95,10.02], ... ['Jacobs', 9.69, 9.71, 9.81], ['Jonhson', 9.65, 9.72, 9.64, 9.74], ... ['Omanyala', 9.72, 9.71, 9.68, 9.74], ['Silva', 9.81, 9.76, 9.77]] >>> min_time(ltime) [9.58, 9.64, 9.68, 9.69, 9.74, 9.76, 9.91, 9.95] >>> min_time(ltime[:4]) [9.58, 9.74, 9.91, 9.95] >>> min_time(ltime[:6]) [9.58, 9.64, 9.69, 9.74, 9.91, 9.95]
Note
More tests are provided in the
test-race1.txtfile.Write the function
min_time_ath()that takes alistas described in the initial paragraph, and returns another nestedlistcorresponding to the same athletes as in the given list and in the same order. The sublists in the returned nested list will have two elements: the name of the athlete (str) and his minimum time (float). See the following examples:>>> ltime = [['Bolt',9.74,9.82,9.58,10.02],['Carter',10.05,10.0,9.91], ... ['Powell',9.93,9.9,9.74],['Gatlin',10.01,9.95,10.02], ... ['Jacobs', 9.69, 9.71, 9.81], ['Jonhson', 9.65, 9.72, 9.64, 9.74], ... ['Omanyala', 9.72, 9.71, 9.68, 9.74], ['Silva', 9.81, 9.76, 9.77]] >>> min_time_ath(ltime) [['Bolt', 9.58], ['Carter', 9.91], ['Powell', 9.74], ['Gatlin', 9.95], ['Jacobs', 9.69], ['Jonhson', 9.64], ['Omanyala', 9.68], ['Silva', 9.76]] >>> min_time_ath(ltime[:4]) [['Bolt', 9.58], ['Carter', 9.91], ['Powell', 9.74], ['Gatlin', 9.95]] >>> min_time_ath(ltime[:6]) [['Bolt', 9.58], ['Carter', 9.91], ['Powell', 9.74], ['Gatlin', 9.95], ['Jacobs', 9.69], ['Jonhson', 9.64]]
Note
More tests are provided in the
test-race2.txtfile.Now we have a
listwith the names of several athletes (str) sorted by arrival order in a race (the winner is the first of the list). Write functionposition()that takes alistof athletes names and a name of an athlete (str), and returns the position (int) in which he has arrived. If the athlete is not in the list, the function will return 0. See the following examples:>>> lc = ['Bolt','Carter','Gatlin','Powell'] >>> position(lc,'Carter') 2 >>> position(lc,'Powell') 4 >>> position(lc,'Johnson') 0 >>> position([],'Carter') 0
Note
More tests are provided in the
test-race3.txtfile.We have a
listwith the names of several athletes (str) sorted inversely by arrival order in a race (the winner is the last of the list). Write functionpodium()that from such a list of names returns anotherlistwith the name of the three first athletes sorted by arrival order. Suppose that the given list has a minimum of three athletes. See the following examples:>>> lc = ['Johnson', 'Bolt','Carter','Gatlin','Powell'] >>> podium(lc) ['Powell', 'Gatlin', 'Carter'] >>> lc1 = ['Johnson', 'Jacobs','Carter', 'Silva', 'Gatlin','Bolt'] >>> podium(lc1) ['Bolt', 'Gatlin', 'Silva']
Note
More tests are provided in the
test-race4.txtfile.
Solutions
A solution of these functions is provided in file
race.py