I have written a function to perform a calculation based on two values taken from a list and then append the result. I want to know how to adapt this function to perform the calculation on all lists within a list of lists, so far I have met with dismal failure.
This is what I know works so far:
import datetime
Horse = ['Sea Biscuit', '10:57:06', '10:58:42']
#My Function used to get times from the list and calculate speed in MPH
def get_speed():
time1 = Horse[1]
time2 = Horse[2]
d = 1 #Assuming a distance of 1 mile
FMT = '%H:%M:%S'
tdelta = datetime.datetime.strptime(time2, FMT) - datetime.datetime.strptime(time1, FMT)
#Convert from timedelta HH:MM:SS format to hours by first converting to a string
stringtime=str(tdelta)
parts = stringtime.split(':')
hours = int(parts[0])*1 + int(parts[1])/60 + int(parts[2])/3600
speed = round((d/hours),2)
Horse.append (speed)
get_speed()
So the list of lists I want to adapt this function to looks like this:
Horses = [['Sea Biscuit', '10:57:06', '10:58:42']['Red Rum', '10:57:06', '10:59:02']['Blazing saddles', '10:57:06', '10:59:16']]
Many thanks for suggestions and help