Let's break the problem down into parts. First, we need a function that can convert each element from the mm:ss.dd format to ss.dd. That's pretty easy to do:
def convert(s):
mins, secs = s.split(':')
mins = int(mins)
secs = float(secs)
secs = 60 * mins + secs
return secs
It seems we can just use map
to convert the elements of the list:
converted_times = map(convert, orig_times)
However, convert
takes a single element (e.g., '0:00.762'
), whereas the data is actually a list of lists -- specifically, a list of pairs. We need another function that accepts a pair of elements (as a list) and returns them. We also want to return them as a string rather than a float:
def convert_pair(p):
p0, p1 = convert(p[0]), convert(p[1])
return [str(p0), str(p1)]
Putting this together, we can simply do
converted_times = map(convert_pair, orig_times)
to transform the list of data pairs.
A sample of this code can be found here.