Skip to content

Instantly share code, notes, and snippets.

@dnorton
Created February 16, 2018 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnorton/a07380fbbc870cb1bdcf8155bdfabc6a to your computer and use it in GitHub Desktop.
Save dnorton/a07380fbbc870cb1bdcf8155bdfabc6a to your computer and use it in GitHub Desktop.
python methods to parse a list of mile times in the format "MM:SS"
"""Script to add up minutes:seconds and give average pace"""
def sum_times(*times):
'''arg list of MM:SS'''
return sum(map(lambda x: int(x.split(':')[0]) * 60 + int(x.split(':')[1]), times)), len(times)
def secs_to_mins(seconds, count):
print "total time: {0:02d}:{1:02d}".format(seconds / 60, seconds % 60)
print "Average pace {0:02d}:{1:02d}".format((seconds/count) / 60, (seconds/count) % 60)
if __name__ == "__main__":
ts, count = sum_times("7:51", "6:59", "6:43")
# secs_to_mins(ts, count)
secs_to_mins(ts, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment