Problem 9 (200pts): time_per_word
Implement time_per_word
, which takes in a list words
and times_per_player
, a list of lists for each player with timestamps indicating when each player finished typing every individual word in words
.
It returns a game
with the given information.
A game
is a data abstraction that has a list of words
and times
. The times
are stored as a list of lists of how long it took each player to type each word.
Specifically, times[i][j]
indicates how long it took player i
to type words[j]
.
For example, say words = ['Hello', 'world']
and times = [[5, 1], [4, 2]]
, then [5, 1]
corresponds to the list of times for player 0, and [4, 2]
corresponds to the list of times for player 1.
Thus, player 0 took 5 units of time to write the word 'Hello'
.
Important: Be sure to use the
game
constructor when returning agame
. The tests will check that you are using thegame
dictionary rather than assuming a particular data format.Read the definitions for the
game
constructor incats.py
to learn more about how the dictionary is implemented.
Timestamps are cumulative and always increasing, while the values in times
are differences between consecutive timestamps for each player.
Here's an example: If times_per_player = [[1, 3, 5], [2, 5, 6]]
, the corresponding times
attribute of the game
would be [[2, 2], [3, 1]]
.
This is because the differences in timestamps are (3-1)
, (5-3)
for the first player and (5-2)
, (6-5)
for the second player.
The first value of each list within times_per_player
represents the initial starting time for each player.
Before writing any code, unlock the tests to verify your understanding of the question:
$ python ok -q 09 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q 09