Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Annotated solution in Clear category for The Fastest Horse by BootzenKatzen
from statistics import mode #for finding the most frequent winner
def fastest_horse(races: list) -> int:
winners = [] # creating empty list to add winners for each race
for race in races: # for each race
for horse, time in enumerate(race, 1): # iterate through the race times, and # the horses (starting @ 1)
if time == min(race): # if the time is equal to the fastest time in the race
winners.append(horse) # add the horse's number to the winners list
return mode(winners) # return the horse with the most frequent wins
if __name__ == '__main__':
print("Example:")
print(fastest_horse([['1:13', '1:26', '1:11']]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert fastest_horse([['1:13', '1:26', '1:11'], ['1:10', '1:18', '1:14'], ['1:20', '1:23', '1:15']]) == 3
print("Coding complete? Click 'Check' to earn cool rewards!")
Aug. 24, 2023