Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Fastest Horse by aya.kanazawa
def fastest_horse(races: list) -> int:
result_dict = {}
for race in races:
time_dict = {horse_number + 1: int(time.split(':')[0])*60 + int(time.split(':')[1]) for horse_number, time in enumerate(race)}
winner = min(time_dict, key=time_dict.get)
result_dict[winner] = result_dict.setdefault(winner, 0) + 1
return max(result_dict, key=result_dict.get)
if __name__ == '__main__':
print("Example:")
assert fastest_horse([['1:13', '1:26', '1:11'], ['1:10', '1:18', '1:14'], ['1:20', '1:23', '1:15']]) == 3
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!")
May 25, 2019